public void CancelIO()
{
CancellationTokenSource cancellationTokenSourceSnapshot = null;
lock (_thisLock)
{
if (_operationsOutstanding == 0)
{
return;
}
cancellationTokenSourceSnapshot = _cancellationTokenSource;
}
if (cancellationTokenSourceSnapshot != null)
{
try
{
cancellationTokenSourceSnapshot.Cancel();
}
catch (ObjectDisposedException)
{
// Simply ignore this exception - There is apparently a rare race condition
// where the cancellationTokensource is disposed before the Cancel method call completed.
}
}
}