public void WaitIfStalled()
{
if (Stalled)
{
lock (this)
{
if (Stalled) // react on the first wakeup call!
{
// don't loop here, higher level logic will re-stall!
try
{
Debug.Assert(IncWaiters());
Monitor.Wait(this);
Debug.Assert(DecrWaiters());
}
catch (ThreadInterruptedException e)
{
throw new ThreadInterruptedException(e);
}
}
}
}
}