public bool WaitUntilDone()
{
lock (this)
{
// Wait for either completion or cancellation. As with
// CancelAndWait, we don't sleep forever - to reduce the
// chances of deadlock in obscure race conditions, we wake
// up every second to check we didn't miss a Pulse.
while (!IsDone)
{
Monitor.Wait(this, 1000);
}
}
return HasCompleted;
}