File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,8 @@ public OutputHandler(TextWriter output)
19
19
_output = output ;
20
20
_queue = new BlockingCollection < object > ( ) ;
21
21
_cancel = new CancellationTokenSource ( ) ;
22
- _thread = new Thread ( ProcessOutputQueue ) {
22
+ _thread = new Thread ( ProcessOutputQueue )
23
+ {
23
24
IsBackground = true
24
25
} ;
25
26
}
@@ -37,11 +38,11 @@ public void Send(object value)
37
38
private void ProcessOutputQueue ( )
38
39
{
39
40
var token = _cancel . Token ;
40
- while ( true )
41
+ try
41
42
{
42
- if ( _thread == null ) return ;
43
- try
43
+ while ( true )
44
44
{
45
+ if ( _thread == null ) return ;
45
46
if ( _queue . TryTake ( out var value , Timeout . Infinite , token ) )
46
47
{
47
48
var content = JsonConvert . SerializeObject ( value ) ;
@@ -55,8 +56,14 @@ private void ProcessOutputQueue()
55
56
_output . Write ( sb . ToString ( ) ) ;
56
57
}
57
58
}
58
- catch ( OperationCanceledException ) { }
59
59
}
60
+ catch ( OperationCanceledException ex )
61
+ {
62
+ if ( ex . CancellationToken != token )
63
+ throw ;
64
+ // else ignore. Exceptions: OperationCanceledException - The CancellationToken has been canceled.
65
+ }
66
+ finally { _cancel . Dispose ( ) ; }
60
67
}
61
68
62
69
public void Dispose ( )
You can’t perform that action at this time.
0 commit comments