如何将消息从Windows服务发送到Windows窗体应用程序? [英] How to send a message from Windows Service to Windows Form application?

查看:479
本文介绍了如何将消息从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.


这篇关于如何将消息从Windows服务发送到Windows窗体应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆