mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Use Cancellation Token to avoid potential race tracing issue
This commit is contained in:
parent
eb5e9dd4be
commit
0ceefea2dd
1 changed files with 4 additions and 3 deletions
|
|
@ -241,7 +241,7 @@ namespace Flow.Launcher.Core.Plugin
|
||||||
protected async Task<Stream> ExecuteAsync(ProcessStartInfo startInfo, CancellationToken token = default)
|
protected async Task<Stream> ExecuteAsync(ProcessStartInfo startInfo, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
Process process = null;
|
Process process = null;
|
||||||
bool disposed = false;
|
using var exitTokenSource = new CancellationTokenSource();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
process = Process.Start(startInfo);
|
process = Process.Start(startInfo);
|
||||||
|
|
@ -251,6 +251,7 @@ namespace Flow.Launcher.Core.Plugin
|
||||||
return Stream.Null;
|
return Stream.Null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
await using var source = process.StandardOutput.BaseStream;
|
await using var source = process.StandardOutput.BaseStream;
|
||||||
|
|
||||||
var buffer = BufferManager.GetStream();
|
var buffer = BufferManager.GetStream();
|
||||||
|
|
@ -259,7 +260,7 @@ namespace Flow.Launcher.Core.Plugin
|
||||||
{
|
{
|
||||||
// ReSharper disable once AccessToModifiedClosure
|
// ReSharper disable once AccessToModifiedClosure
|
||||||
// Manually Check whether disposed
|
// Manually Check whether disposed
|
||||||
if (!disposed && !process.HasExited)
|
if (!exitTokenSource.IsCancellationRequested && !process.HasExited)
|
||||||
process.Kill();
|
process.Kill();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -302,8 +303,8 @@ namespace Flow.Launcher.Core.Plugin
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
exitTokenSource.Cancel();
|
||||||
process?.Dispose();
|
process?.Dispose();
|
||||||
disposed = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue