@@ -19,11 +19,6 @@ namespace CefSharp.DevTools
19
19
/// </summary>
20
20
public partial class DevToolsClient : IDevToolsMessageObserver , IDevToolsClient
21
21
{
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
-
27
22
private readonly ConcurrentDictionary < int , DevToolsMethodResponseContext > queuedCommandResults = new ConcurrentDictionary < int , DevToolsMethodResponseContext > ( ) ;
28
23
private readonly ConcurrentDictionary < string , EventHandler < Stream > > eventHandlers = new ConcurrentDictionary < string , EventHandler < Stream > > ( ) ;
29
24
private IBrowser browser ;
@@ -138,8 +133,6 @@ public Task<T> ExecuteDevToolsMethodAsync<T>(string method, IDictionary<string,
138
133
throw new ObjectDisposedException ( nameof ( IBrowser ) ) ;
139
134
}
140
135
141
- var messageId = Interlocked . Increment ( ref lastMessageId ) ;
142
-
143
136
var taskCompletionSource = new TaskCompletionSource < T > ( ) ;
144
137
145
138
var methodResultContext = new DevToolsMethodResponseContext (
@@ -149,13 +142,15 @@ public Task<T> ExecuteDevToolsMethodAsync<T>(string method, IDictionary<string,
149
142
syncContext : CaptureSyncContext ? SynchronizationContext . Current : SyncContext
150
143
) ;
151
144
145
+ var browserHost = browser . GetHost ( ) ;
146
+
147
+ var messageId = browserHost . GetNextDevToolsMessageId ( ) ;
148
+
152
149
if ( ! queuedCommandResults . TryAdd ( messageId , methodResultContext ) )
153
150
{
154
151
throw new DevToolsClientException ( string . Format ( "Unable to add MessageId {0} to queuedCommandResults ConcurrentDictionary." , messageId ) ) ;
155
152
}
156
153
157
- var browserHost = browser . GetHost ( ) ;
158
-
159
154
//Currently on CEF UI Thread we can directly execute
160
155
if ( CefThread . CurrentlyOnUiThread )
161
156
{
0 commit comments