22// The .NET Foundation licenses this file to you under the MIT license.
33
44using System ;
5- using System . Collections . Generic ;
5+ using System . Collections . Concurrent ;
66using System . Net ;
77using System . Net . Sockets ;
88using System . Net . WebSockets ;
@@ -17,7 +17,7 @@ namespace DebuggerTests
1717{
1818 internal class InspectorClient : DevToolsClient
1919 {
20- protected Dictionary < MessageId , TaskCompletionSource < Result > > pending_cmds = new Dictionary < MessageId , TaskCompletionSource < Result > > ( ) ;
20+ protected readonly ConcurrentDictionary < MessageId , TaskCompletionSource < Result > > pending_cmds = new ( ) ;
2121 protected Func < string , string , JObject , CancellationToken , Task > onEvent ;
2222 protected int next_cmd_id ;
2323
@@ -39,7 +39,7 @@ protected virtual Task HandleMessage(string msg, CancellationToken token)
3939 return onEvent ( res [ "sessionId" ] ? . Value < string > ( ) , res [ "method" ] . Value < string > ( ) , res [ "params" ] as JObject , token ) ;
4040
4141 var id = res . ToObject < MessageId > ( ) ;
42- if ( ! pending_cmds . Remove ( id , out var item ) )
42+ if ( ! pending_cmds . TryRemove ( id , out var item ) )
4343 logger . LogError ( $ "Unable to find command { id } ") ;
4444
4545 item . SetResult ( Result . FromJson ( res ) ) ;
@@ -95,7 +95,9 @@ public virtual Task<Result> SendCommand(SessionId sessionId, string method, JObj
9595 if ( sessionId != SessionId . Null )
9696 o . Add ( "sessionId" , sessionId . sessionId ) ;
9797 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 ) ;
99101
100102 var str = o . ToString ( ) ;
101103
0 commit comments