在.NET中有什么在同一台机器进行通信两个过程的最佳方法是什么?中有、机器、两个、过程

2023-09-03 00:34:00 作者:谁的年少不轻狂

什么是最好的(也许不是最好的 - 刚刚好)?的方式为在同一台机器进行通信两个过程,使用.NET

What's the best (or maybe not the best -- just good) way for two processes in the same machine to communicate, using .NET?

其实,在应用程序中的两个过程我的工作,甚至没有两个不同的程序;它们是相同的EXE只是两个实例。我想做一些像一个单独的应用程序,但它每个用户(意为终端服务器或Citrix或App-V的服务器与多个用户应该能够启动的应用程序自身的单拷贝)。如果另一个实例是由同一用户运行的,它应该只是将任务委派给已经运行的实例,则退出。每个节目的用户只有一个实例应该运行。到目前为止,我已经做了(感谢计算器),可检测应用程序实例是否已在运行,使用互斥的一部分。但我需要第二个应用程序实例能够将数据发送到第一个应用实例。

Actually the two processes in the app I'm working on aren't even two different programs; they're just two instances of the same EXE. I wanted to do something like a singleton app, but have it per user (meaning a Terminal Server or Citrix or App-V server with multiple users should be able to launch their own single copy of the app). If another instance is run by the same user, it should just delegate the task to the already running instance, then exit. Only one instance per user of the program should be running. So far I've done (thanks to StackOverflow) the part that detects whether an instance of the app is already running, using Mutex. But I need the second app instance to be able to send data to the first app instance.

我倾向于使用命名管道和WCF的NetNamedPipeBinding这一点,但如果你有更好的想法我就会非常AP preciate它。感谢:)

I'm leaning towards using named pipes and WCF's NetNamedPipeBinding for this, but if you have better ideas I'll really appreciate it. Thanks :)

推荐答案

我会去命名管道。

基本上,你需要每个用户一个唯一的端点。正如你互斥,你可能会使用的用户名,找出命名管道使用的名称。这甚至可能会取代你使用互斥的:试图找出是否已存在这个特定的命名管道,如果确实如此,这意味着你的第二个实例运行

Basically, you'll need a unique endpoint per user. As with your Mutex, you'll probably use the username to find out the name of the named pipe to use. This might even replace your use of the Mutex: try to find out if a named pipe for this particular already exists, and if it does, it means you're the second instance to run.

这是很难TCP端口映射到用户。

It's harder to map a TCP port onto a user.

呵呵,并通过使用命名管道,实际上,我说:远程命名管道。

Oh, and by using Named Pipes, I'm actually saying "Remoting over Named Pipes".

 
精彩推荐
图片推荐