Test Test 2Collecting message...Reading pipe async[NORMAL]Discovering patches...[NORMAL]No patches in this directory...[NORMAL]Connecting...[GOOD]ConnectedException thrown: 'System.OperationCanceledException' in System.Core.dllAn exception of type 'System.OperationCanceledException' occurred in System.Core.dll but was not handled in user codeThe operation was canceled.Exception thrown: 'System.OperationCanceledException' in mscorlib.dllException thrown: 'System.OperationCanceledException' in mscorlib.dllException thrown: 'System.OperationCanceledException' in mscorlib.dllException thrown: 'System.OperationCanceledException' in mscorlib.dllCancelled
c# try { var msg = await _protocol.Receive(TimeSpan.FromSeconds(2)); Console.WriteLine(msg.Identifier); } catch (OperationCanceledException) { Console.WriteLine("Cancelled"); }
CancelIoEx
c#private static Task<int> ReadPipeAsync(PipeStream pipe, byte[] buffer, int offset, int count, CancellationToken cancellationToken){ if (cancellationToken.IsCancellationRequested) return Task.FromCanceled<int>(cancellationToken); var registration = cancellationToken.Register(() => CancelPipeIo(pipe)); var result = pipe.BeginRead(buffer, offset, count, null, null); Console.WriteLine("Reading pipe async"); return Task.Run(() => { try { return pipe.EndRead(result); } finally { registration.Dispose(); } }, cancellationToken);}