如何让两个进程进行通信?
我有两个 .net 应用程序。一个是普通的 Windows 窗体应用程序,另一个是 Microsoft Word COM 加载项。我正在使用 C# 开发这两个应用程序。
我需要这两个应用程序来相互通信。我想知道实现这一目标的最佳方法是什么。
我想到的第一件事是我应该使用双向命名管道来执行此操作,但命名管道是系统范围的,我需要将连接限制为同一会话中的进程运行(这可以并且将用于终端服务器)。
有什么方法可以将命名管道限制在当前会话中吗?如果没有,我还有什么选择?
谢谢
I have two .net applications. One is a normal Windows Forms application while the other is a Microsoft Word COM Add-in. I'm developping both applications with C#.
I need theses two application to comunicate with each other. I'm wondering what is the best way to achieve this.
The first thing I though was that I should use a bi-directional named pipe to do this, but named pipes are system-wide and I need the connection to be restricted to process runnings in the same session (This could and will be used on a terminal server).
Is there any way to restrict a named pipe to the current session? If there is not what alternatives do I have?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建本地 Web 服务来实现此目的。
要创建 Web 服务,您必须执行类似以下操作:
当您运行 Web 服务时,您应该看到类似以下内容:
在不同的程序/线程(在本例中为控制台应用程序)上,
您应该能够连接到该服务:
最后输入您刚刚创建的服务的 url:
现在您可以实例化一个来自该类的对象此控制台应用程序的 Service1 如下:
使用此技术,您将能够将大部分任何内容传递到其他应用程序(任何可序列化的内容)。因此,也许您可以将此 Web 服务创建为第三个线程,以使其更有组织性。希望这有帮助。
you can create a local web service to achieve this.
To create your web service you must do something similar to:
when you run your web service you should see something like:
on a different program/thread (in this case console application)
you should be able to connect to that service as:
Lastly type the url of the service you just created:
Now you are able to instantiate an object from that class Service1 from this console application as:
with this technique you will be able to pass mostly anything to your other application (anything that is serializable). so maybe you can create this webservice as a third thread to make it more organized. Hope this helps.