Skip to content

Commit

Permalink
Add note about .NET 7 stream and pipe cancellation
Browse files Browse the repository at this point in the history
  • Loading branch information
menees committed Sep 3, 2022
1 parent 7d820a0 commit 687ad0a
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Menees.Remoting/Models/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ private static async Task<byte[]> RequireReadAsync(Stream stream, int requiredCo

// In .NET Framework the stream.ReadAsync implementation ignores cancellationToken.
// This is a workaround. https://stackoverflow.com/a/12893018/1882616
// .NET 7 adds full support for stream and pipe cancellation.
// https://devblogs.microsoft.com/dotnet/performance_improvements_in_net_7/#file-i-o
using CancellationTokenRegistration registration = cancellationToken.Register(() => stream.Close());

// We'll check cancellation before and after each operation so we don't get an ObjectDisposedException
Expand Down

0 comments on commit 687ad0a

Please sign in to comment.