fix: accessing dummy in multi-threads throws exception

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-03-11 20:05:05 +08:00
parent 2fc03025ee
commit 91c5c96afc
No known key found for this signature in database

View file

@ -73,6 +73,7 @@ namespace SourceGit.Commands
}; };
var dummy = null as Process; var dummy = null as Process;
var dummyProcLock = new object();
try try
{ {
proc.Start(); proc.Start();
@ -83,11 +84,10 @@ namespace SourceGit.Commands
dummy = proc; dummy = proc;
CancellationToken.Register(() => CancellationToken.Register(() =>
{ {
if (dummy is { HasExited: false }) lock (dummyProcLock)
{ {
dummy.CancelErrorRead(); if (dummy is { HasExited: false })
dummy.CancelOutputRead(); dummy.Kill();
dummy.Kill();
} }
}); });
} }
@ -104,7 +104,14 @@ namespace SourceGit.Commands
proc.BeginErrorReadLine(); proc.BeginErrorReadLine();
proc.WaitForExit(); proc.WaitForExit();
dummy = null; if (dummy != null)
{
lock (dummyProcLock)
{
dummy = null;
}
}
int exitCode = proc.ExitCode; int exitCode = proc.ExitCode;
proc.Close(); proc.Close();