Simplify process exit detection.
MODIFY
WalletWasabi/Helpers/ProcessHelpers.cs
WalletWasabi/Helpers/ProcessHelpers.cs
@@ -9,33 +9,12 @@ namespace WalletWasabi.Helpers
{
public static class ProcessHelpers
{
- public static async Task WaitForExitAsync(this Process process, CancellationToken cancellationToken = default)
+ public static async Task WaitForExitAsync(this Process process, CancellationToken cancellationToken)
{
- var tcs = new TaskCompletionSource<bool>();
-
- void Process_Exited(object sender, EventArgs e)
- {
- Task.Run(() => tcs.TrySetResult(true));
- }
-
- process.EnableRaisingEvents = true;
- process.Exited += Process_Exited;
-
- try
- {
- if (process.HasExited)
- {
- return;
- }
-
- using (cancellationToken.Register(() => Task.Run(() => tcs.TrySetCanceled())))
- {
- await tcs.Task;
- }
- }
- finally
+ while (!cancellationToken.IsCancellationRequested)
{
- process.Exited -= Process_Exited;
+ await Task.Delay(500);
+ if (process.HasExited) break;
}
}
}

MODIFY
WalletWasabi/Hwi/HwiProcessManager.cs
WalletWasabi/Hwi/HwiProcessManager.cs
@@ -161,7 +161,11 @@ namespace WalletWasabi.Hwi
}
))
{
- await process.WaitForExitAsync();
+ using (var cancel = new CancellationTokenSource(TimeSpan.FromSeconds(60)))
+ {
+ await process.WaitForExitAsync(cancel.Token);
+ }
+
if (process.ExitCode != 0)
{
throw new IOException($"Command: {command} exited with exit code: {process.ExitCode}, instead of 0.");

Simplify process exit detection.