File tree Expand file tree Collapse file tree 1 file changed +4
-6
lines changed Expand file tree Collapse file tree 1 file changed +4
-6
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ namespace JsonRpc
10
10
public class OutputHandler : IOutputHandler
11
11
{
12
12
private readonly TextWriter _output ;
13
- private Thread _thread ;
13
+ private readonly Thread _thread ;
14
14
private readonly BlockingCollection < object > _queue ;
15
15
private readonly CancellationTokenSource _cancel ;
16
16
@@ -41,7 +41,6 @@ private void ProcessOutputQueue()
41
41
{
42
42
while ( true )
43
43
{
44
- if ( _thread == null ) return ;
45
44
if ( _queue . TryTake ( out var value , Timeout . Infinite , token ) )
46
45
{
47
46
var content = JsonConvert . SerializeObject ( value ) ;
@@ -51,7 +50,6 @@ private void ProcessOutputQueue()
51
50
sb . Append ( $ "Content-Length: { content . Length } \r \n ") ;
52
51
sb . Append ( $ "\r \n ") ;
53
52
sb . Append ( content ) ;
54
-
55
53
_output . Write ( sb . ToString ( ) ) ;
56
54
}
57
55
}
@@ -62,14 +60,14 @@ private void ProcessOutputQueue()
62
60
throw ;
63
61
// else ignore. Exceptions: OperationCanceledException - The CancellationToken has been canceled.
64
62
}
65
- finally { _cancel . Dispose ( ) ; }
66
63
}
67
64
68
65
public void Dispose ( )
69
66
{
70
- _output ? . Dispose ( ) ;
71
- _thread = null ;
72
67
_cancel . Cancel ( ) ;
68
+ _thread . Join ( ) ;
69
+ _cancel . Dispose ( ) ;
70
+ _output . Dispose ( ) ;
73
71
}
74
72
}
75
73
}
You can’t perform that action at this time.
0 commit comments