I have a system-wide manual reset event that I create by doing the following:
EventWaitHandle notifyEvent = new EventWaitHandle(false, EventResetMode.ManualReset, notifyEventName, out createdEvent);
Several processes create this event (for example, it is common to them). It is used to notify when something is updated.
I would like to be able to set this event so that all processes waiting for it are signaled, and then immediately reset so that subsequent expectations in the event are blocked.
If i do
notifyEvent.Set(); notifyEvent.Reset();
Sometimes it notifies all listening processes.
If i do
notifyEvent.Set(); Thread.Sleep(0); notifyEvent.Reset();
Additional processes receive a notification (I assumed that this will happen, since the scheduler has the ability to run).
And if I do
notifyEvent.Set(); Thread.Sleep(100); notifyEvent.Reset();
Then everything seems to work fine, and all processes (like ~ 8) get notified sequentially. I do not like using the "magic number" to call sleep.
Is there a better way to notify all listeners about an OS event in other processes that an event has occurred, so that everyone who listens to it during the notification receives an event signal, and then immediately reset the event so that anyone else that goes to listen will to block?
UPDATE: The semaphore does not seem to be very good here, as the number of listeners for the event may change over time. It is not known in advance how many listeners will be there when you even need to be informed about it.
multithreading c # windows events
Jeff moser
source share