2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
4
using System ;
5
- using System . Collections . Generic ;
5
+ using System . Collections . Concurrent ;
6
6
using System . Net ;
7
7
using System . Net . Sockets ;
8
8
using System . Net . WebSockets ;
@@ -17,7 +17,7 @@ namespace DebuggerTests
17
17
{
18
18
internal class InspectorClient : DevToolsClient
19
19
{
20
- protected Dictionary < MessageId , TaskCompletionSource < Result > > pending_cmds = new Dictionary < MessageId , TaskCompletionSource < Result > > ( ) ;
20
+ protected readonly ConcurrentDictionary < MessageId , TaskCompletionSource < Result > > pending_cmds = new ( ) ;
21
21
protected Func < string , string , JObject , CancellationToken , Task > onEvent ;
22
22
protected int next_cmd_id ;
23
23
@@ -39,7 +39,7 @@ protected virtual Task HandleMessage(string msg, CancellationToken token)
39
39
return onEvent ( res [ "sessionId" ] ? . Value < string > ( ) , res [ "method" ] . Value < string > ( ) , res [ "params" ] as JObject , token ) ;
40
40
41
41
var id = res . ToObject < MessageId > ( ) ;
42
- if ( ! pending_cmds . Remove ( id , out var item ) )
42
+ if ( ! pending_cmds . TryRemove ( id , out var item ) )
43
43
logger . LogError ( $ "Unable to find command { id } ") ;
44
44
45
45
item . SetResult ( Result . FromJson ( res ) ) ;
@@ -95,7 +95,9 @@ public virtual Task<Result> SendCommand(SessionId sessionId, string method, JObj
95
95
if ( sessionId != SessionId . Null )
96
96
o . Add ( "sessionId" , sessionId . sessionId ) ;
97
97
var tcs = new TaskCompletionSource < Result > ( ) ;
98
- pending_cmds [ new MessageId ( sessionId . sessionId , id ) ] = tcs ;
98
+
99
+ MessageId msgId = new MessageId ( sessionId . sessionId , id ) ;
100
+ pending_cmds . AddOrUpdate ( msgId , tcs , ( key , oldValue ) => tcs ) ;
99
101
100
102
var str = o . ToString ( ) ;
101
103
0 commit comments