Skip to content

Commit

Permalink
Synchronize access to StringBuilders. Fixes #8
Browse files Browse the repository at this point in the history
  • Loading branch information
bgrainger committed Mar 15, 2021
1 parent bb2ad76 commit 65a7f08
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/CloneLeeroy/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,19 @@ private static string VerifySuccess((int ExitCode, string Stdout, string Stderr)
foreach (var argument in arguments)
process.StartInfo.ArgumentList.Add(argument);

var lck = new object();
var output = new StringBuilder();
var error = new StringBuilder();
process.OutputDataReceived += (sender, args) => output.Append(args.Data + Environment.NewLine);
process.ErrorDataReceived += (sender, args) => error.Append(args.Data + Environment.NewLine);
process.OutputDataReceived += (sender, args) =>
{
lock (lck)
output.Append(args.Data + Environment.NewLine);
};
process.ErrorDataReceived += (sender, args) =>
{
lock (lck)
error.Append(args.Data + Environment.NewLine);
};

if (!process.Start())
throw new InvalidOperationException("Couldn't start git");
Expand All @@ -227,7 +236,8 @@ private static string VerifySuccess((int ExitCode, string Stdout, string Stderr)

await process.WaitForExitAsync();

return (process.ExitCode, output.ToString(), error.ToString());
lock (lck)
return (process.ExitCode, output.ToString(), error.ToString());
}

private static ScopedConsoleColor SetColor(ConsoleColor color)
Expand Down

0 comments on commit 65a7f08

Please sign in to comment.