The invocation of Monitor.Wait(...)
is not enclosed by a while
loop. However, code that uses this method usually waits for a particular state. It becomes more problematic when using it in conjunction with Monitor.PulseAll(...)
. Since it is not possible to specify which thread to notify, it may notify threads that wait for a different state.
Enclose the Monitor.Wait(...)
invocation with a while
loop that loops as long as the expected state has not been satisfied.
while(!isReady) {
Monitor.Wait(syncObject);
}