From 687ad0a328ae4d7cb7be7a1ecb4c89ff9e180d57 Mon Sep 17 00:00:00 2001 From: Bill Menees Date: Fri, 2 Sep 2022 20:35:56 -0500 Subject: [PATCH] Add note about .NET 7 stream and pipe cancellation --- src/Menees.Remoting/Models/Message.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Menees.Remoting/Models/Message.cs b/src/Menees.Remoting/Models/Message.cs index 4c30e1c..9c7a6cf 100644 --- a/src/Menees.Remoting/Models/Message.cs +++ b/src/Menees.Remoting/Models/Message.cs @@ -118,6 +118,8 @@ private static async Task 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