tags:

views:

95

answers:

1

Hi all,

when creating a named EventWaitHandle in each process you can specifiy in which state it should be. Now this somehow contradicts the assumption that the EventWaitHandle is usable for IPC as another process might have set the state to "signalled" whereas I (when creating the EventWaitHandle) can set it to "not signalled".

Any ideas?

thanks, Chris

+1  A: 

Did you read the documentation?

From the page:

When using this constructor for named system events, specify false for initialState. This constructor provides no way to determine whether a named system event was created, so you cannot make any assumptions about the state of the named event. To determine whether a named event was created, use the EventWaitHandle(Boolean, EventResetMode, String, Boolean) constructor or the EventWaitHandle(Boolean, EventResetMode, String, Boolean, EventWaitHandleSecurity) constructor.

If that is the constructor you're using, then the documentation for thaf constructor indicates that the initialState flag is only used when your call creates the event.

Adam Robinson
Well, I thought this referse to the creating state. So there is no chance to know in which state the event is unless you have created it?
Christoph
Makes sense, thanks!
Christoph
@Christoph: No, you can't know which state it's in, *even if you explicitly created it*. It's entirely possible that between the time you created the event and when the next line of code is executed, someone has attached to the event and changed the state. There is no way to explicitly check (or even know) the state of an event, all you can do is set, reset, and wait.
Adam Robinson
@Christoph: Additionally, if this answer has answered your question, please don't forget to accept it so that others browsing the site with similar questions will know that this solved your problem.
Adam Robinson