@@ -26,9 +26,11 @@ internal class ProcessEx : IDisposable
26
26
private readonly StringBuilder _stderrCapture ;
27
27
private readonly StringBuilder _stdoutCapture ;
28
28
private readonly object _pipeCaptureLock = new object ( ) ;
29
+ private readonly object _testOutputLock = new object ( ) ;
29
30
private BlockingCollection < string > _stdoutLines ;
30
31
private TaskCompletionSource < int > _exited ;
31
32
private CancellationTokenSource _stdoutLinesCancellationSource = new CancellationTokenSource ( TimeSpan . FromMinutes ( 5 ) ) ;
33
+ private bool _disposed = false ;
32
34
33
35
public ProcessEx ( ITestOutputHelper output , Process proc )
34
36
{
@@ -135,7 +137,13 @@ private void OnErrorData(object sender, DataReceivedEventArgs e)
135
137
_stderrCapture . AppendLine ( e . Data ) ;
136
138
}
137
139
138
- _output . WriteLine ( "[ERROR] " + e . Data ) ;
140
+ lock ( _testOutputLock )
141
+ {
142
+ if ( ! _disposed )
143
+ {
144
+ _output . WriteLine ( "[ERROR] " + e . Data ) ;
145
+ }
146
+ }
139
147
}
140
148
141
149
private void OnOutputData ( object sender , DataReceivedEventArgs e )
@@ -150,7 +158,13 @@ private void OnOutputData(object sender, DataReceivedEventArgs e)
150
158
_stdoutCapture . AppendLine ( e . Data ) ;
151
159
}
152
160
153
- _output . WriteLine ( e . Data ) ;
161
+ lock ( _testOutputLock )
162
+ {
163
+ if ( ! _disposed )
164
+ {
165
+ _output . WriteLine ( e . Data ) ;
166
+ }
167
+ }
154
168
155
169
if ( _stdoutLines != null )
156
170
{
@@ -204,6 +218,11 @@ private static string GetNugetPackagesRestorePath() => (string.IsNullOrEmpty(Env
204
218
205
219
public void Dispose ( )
206
220
{
221
+ lock ( _testOutputLock )
222
+ {
223
+ _disposed = true ;
224
+ }
225
+
207
226
if ( _process != null && ! _process . HasExited )
208
227
{
209
228
_process . KillTree ( ) ;
0 commit comments