Skip to content

Commit ddb25a2

Browse files
committed
Unregister Cancellation Event by disposing the delegate
1 parent c3dd3b1 commit ddb25a2

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Flow.Launcher.Infrastructure;
44
using System;
55
using System.Collections.Generic;
6+
using System.ComponentModel;
67
using System.Diagnostics;
78
using System.IO;
89
using System.Linq;
@@ -254,24 +255,17 @@ protected async Task<Stream> ExecuteAsync(ProcessStartInfo startInfo, Cancellati
254255
return Stream.Null;
255256
}
256257

257-
258-
259258
var sourceBuffer = BufferManager.GetStream();
260-
var errorBuffer = BufferManager.GetStream();
259+
using var errorBuffer = BufferManager.GetStream();
261260

262261
var sourceCopyTask = process.StandardOutput.BaseStream.CopyToAsync(sourceBuffer, token);
263262
var errorCopyTask = process.StandardError.BaseStream.CopyToAsync(errorBuffer, token);
264-
265-
token.Register(() =>
263+
264+
await using var registeredEvent = token.Register(() =>
266265
{
267-
try
268-
{
269-
if (!process.HasExited)
270-
process.Kill();
271-
}
272-
catch (InvalidOperationException)
273-
{
274-
}
266+
if (!process.HasExited)
267+
process.Kill();
268+
sourceBuffer.Dispose();
275269
});
276270

277271
try
@@ -303,7 +297,7 @@ protected async Task<Stream> ExecuteAsync(ProcessStartInfo startInfo, Cancellati
303297
if (errorBuffer.Length != 0)
304298
{
305299
using var error = new StreamReader(errorBuffer);
306-
300+
307301
var errorMessage = await error.ReadToEndAsync();
308302

309303
if (!string.IsNullOrEmpty(errorMessage))

0 commit comments

Comments
 (0)