Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub committed Sep 10, 2016
1 parent 7d41d78 commit 119c770
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/System.IO.FileSystem/src/System/IO/Win32FileStream.cs
Expand Up @@ -1764,22 +1764,25 @@ private async Task AsyncModeCopyToAsync(Stream destination, int bufferSize, Canc
// whatever read operation may currently be in progress, if there is one. It's possible the cancellation
// request could come in between operations, in which case we flag that with explicit calls to ThrowIfCancellationRequested
// in the read/write copy loop.
cancellationReg = cancellationToken.Register(s =>
if (cancellationToken.CanBeCanceled)
{
var innerAwaitable = (AsyncCopyToAwaitable)s;
unsafe
cancellationReg = cancellationToken.Register(s =>
{
lock (innerAwaitable.CancellationLock) // synchronize with cleanup of the overlapped
var innerAwaitable = (AsyncCopyToAwaitable)s;
unsafe
{
if (innerAwaitable._nativeOverlapped != null)
{
// Try to cancel the I/O. We ignore the return value, as cancellation is opportunistic and we
// don't want to fail the operation because we couldn't cancel it.
Interop.mincore.CancelIoEx(innerAwaitable._fileStream._handle, innerAwaitable._nativeOverlapped);
lock (innerAwaitable.CancellationLock) // synchronize with cleanup of the overlapped
{
if (innerAwaitable._nativeOverlapped != null)
{
// Try to cancel the I/O. We ignore the return value, as cancellation is opportunistic and we
// don't want to fail the operation because we couldn't cancel it.
Interop.mincore.CancelIoEx(innerAwaitable._fileStream._handle, innerAwaitable._nativeOverlapped);
}
}
}
}
}, readAwaitable);
}, readAwaitable);
}

// Repeatedly read from this FileStream and write the results to the destination stream.
while (true)
Expand Down

0 comments on commit 119c770

Please sign in to comment.