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