如何将消息从Windows服务发送到Windows窗体应用程序?

如何将消息从Windows服务发送到Windows窗体应用程序?

问题描述:

我有两个应用程序,一个是 Windows服务,第二个是 Windows Forms 应用程序.从Windows服务向Windows窗体发送消息(长度为10个字符的小字符串)的最佳方法是什么.

任何简单的方法都受到高度赞赏.

谢谢,
Kishore

I have two applications, one Windows Service, second Windows Forms application. What would be the best way to send a message (its a small string 10 character length) from Windows Service to Windows Forms.

Any simple approach is highly appreciated.

Thanks,
Kishore

您可以使用通用存储来更新它.将您的数据放在注册表/磁盘文件中或任何您想要的位置,然后从两个过程中访问它们.这是最简单的.

除此之外,您还可以使用命名管道在两个进程之间发送消息.阅读此内容:

http://www.switchonthecode.com/tutorials/interprocess-communication-using- named-pipes-in-csharp [ ^ ]
http://www.codeguru.com/Csharp/Csharp/cs_network/remoting/article .php/c7259/ [ ^ ]

;)
You might use common storage to update this. Place your data in Registry / diskfile or whereever you want, and access it from both the process. This is the easiest.

Other than that, you might also use Named Pipes to send messages between two processes. Read this :

http://www.switchonthecode.com/tutorials/interprocess-communication-using-named-pipes-in-csharp[^]
http://www.codeguru.com/Csharp/Csharp/cs_network/remoting/article.php/c7259/[^]

;)


我认为最简单的方法是在您的表单中具有一个查询服务并返回值的函数.

您可以将其放入线程或计时器中.

我同意答案2.
I think the simplest would be to have a function in your form that queries the service, and returns the value.

You can put it in a thread, or a timer.

I Agree With Answer 2.