protected override void Execute()
{
try
{
switch (WaitHandle.WaitAny(new[] {_waitHandle, CancellationToken.WaitHandle}, _millisecondsTimeout, exitContext: false))
{
case 0:
State = TaskState.Complete;
break;
case 1:
throw new OperationCanceledException();
default:
case WaitHandle.WaitTimeout:
throw new TimeoutException();
}
}
catch (AbandonedMutexException ex)
{
// Abandoned mutexes also get owned, but indicate something may have gone wrong elsewhere
Log.Warn(ex.Message);
State = TaskState.Complete;
}
}
}