From 220db44a6c42ced03fbdf2cbbbe065143d07e2cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=BC=98=E9=9F=AC?= Date: Tue, 27 Jul 2021 13:54:13 +0800 Subject: [PATCH] Manually kill process when token is canceled --- Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs b/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs index 58bd40807..59980a611 100644 --- a/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs +++ b/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs @@ -243,9 +243,18 @@ namespace Flow.Launcher.Core.Plugin return Stream.Null; } - var source = process.StandardOutput.BaseStream; + await using var source = process.StandardOutput.BaseStream; var buffer = BufferManager.GetStream(); + bool disposed = false; + process.Disposed += (_, _) => { disposed = true; }; + token.Register(() => + { + if (!disposed) + // ReSharper disable once AccessToDisposedClosure + // Manually Check whether disposed + process.Kill(); + }); try { @@ -260,7 +269,7 @@ namespace Flow.Launcher.Core.Plugin buffer.Seek(0, SeekOrigin.Begin); token.ThrowIfCancellationRequested(); - + if (!process.StandardError.EndOfStream) { using var standardError = process.StandardError;