@@ -19,11 +19,6 @@ namespace CefSharp.DevTools
1919 /// </summary>
2020 public partial class DevToolsClient : IDevToolsMessageObserver , IDevToolsClient
2121 {
22- //TODO: Message Id is now global, limits the number of messages to int.MaxValue
23- //Needs to be unique and incrementing per browser with the option to have multiple
24- //DevToolsClient instances per browser.
25- private static int lastMessageId = 0 ;
26-
2722 private readonly ConcurrentDictionary < int , DevToolsMethodResponseContext > queuedCommandResults = new ConcurrentDictionary < int , DevToolsMethodResponseContext > ( ) ;
2823 private readonly ConcurrentDictionary < string , EventHandler < Stream > > eventHandlers = new ConcurrentDictionary < string , EventHandler < Stream > > ( ) ;
2924 private IBrowser browser ;
@@ -138,8 +133,6 @@ public Task<T> ExecuteDevToolsMethodAsync<T>(string method, IDictionary<string,
138133 throw new ObjectDisposedException ( nameof ( IBrowser ) ) ;
139134 }
140135
141- var messageId = Interlocked . Increment ( ref lastMessageId ) ;
142-
143136 var taskCompletionSource = new TaskCompletionSource < T > ( ) ;
144137
145138 var methodResultContext = new DevToolsMethodResponseContext (
@@ -149,13 +142,15 @@ public Task<T> ExecuteDevToolsMethodAsync<T>(string method, IDictionary<string,
149142 syncContext : CaptureSyncContext ? SynchronizationContext . Current : SyncContext
150143 ) ;
151144
145+ var browserHost = browser . GetHost ( ) ;
146+
147+ var messageId = browserHost . GetNextDevToolsMessageId ( ) ;
148+
152149 if ( ! queuedCommandResults . TryAdd ( messageId , methodResultContext ) )
153150 {
154151 throw new DevToolsClientException ( string . Format ( "Unable to add MessageId {0} to queuedCommandResults ConcurrentDictionary." , messageId ) ) ;
155152 }
156153
157- var browserHost = browser . GetHost ( ) ;
158-
159154 //Currently on CEF UI Thread we can directly execute
160155 if ( CefThread . CurrentlyOnUiThread )
161156 {
0 commit comments