事件可以是进程间的吗? [英] Can Events be Inter-Process?

查看:123
本文介绍了事件可以是进程间的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在一个进程中创建了一个事件并进行测试,然后通过管道将事件句柄发送到一个完全独立的进程(而不是子线程)

I have created an event in one process and to test, sent the event handle via a pipe to a totally separate process (not a child thread)

当我在第一个事件中触发该事件时,WaitForSingleObject不会检测到该事件,因此我猜答案是否定的,除非我错过了

When I fire the event in the first, WaitForSingleObject does not detect the event so I am guessing the answer is no unless I missed some trick in the SECURITY_ATTRIBUTES structure?

或者也许我需要使用命名事件并调用OpenEvent()?

Or perhaps I need to use a named event and call OpenEvent()?

在这种情况下,我无法使用窗口消息,因为我试图向Windows服务发出信号.我可以使用管道,但是会有很多这样的应用程序,如果可能的话,我想找到一个低成本"的解决方案.

In this case I cannot use window messages because I am trying to signal a windows service. I could use the pipe, but there will be many of these applications, and I would like to find a "low cost" solution if possible.

内存映射文件"之类的其他选项比管道还具有更多开销吗?

Other options like Memory mapped files have even more overhead than the pipe?

您将如何做?

推荐答案

您需要创建一个命名事件并在两个进程中都将其打开.如果您有多个进程在监听,则可以考虑使用信号灯.

You need to create a named event and open it in both processes. If you have multiple processes listening, you may consider using a semaphore.

这篇关于事件可以是进程间的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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