What (I think) I want is the equivalent of an AutoResetEvent that can wait for multiple threads, and all of this will resume when it is installed.
I know this can be achieved by having an AutoResetEvent for each thread and setting each one - but is there an easier way? A way that doesn't depend on event descriptor arrays?
Effectively, that (I think), I would like this to be possible:
private volatile string state; private MultiEventHandle stateChanged = new MultiEventHandle(); public void WaitForBlob() { while (true) { object saved = stateChanged.Current;
that is, any number of threads can call WaitForBlob , and at any time (without race conditions) SetBlob can be called by another thread, and all waiting threads will immediately detect a change, and, importantly, without spin locks or Threading.Sleeps.
Now I think that I can implement " MultiEventHandle " relatively easily. But my question is ... is there a better way? Of course, I'm going to do it wrong, as this should be a fairly common use case, but I cannot find a built-in tool to work. I'm afraid I'm probably going to come up with a square wheel here.
source share