Skip to content

Commit ad02fff

Browse files
joaompnevesamaitland
authored andcommitted
Fixed crash accessing js objects dictionary concurrently
1 parent ee5b8dd commit ad02fff

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

CefSharp/Internals/JavascriptObjectRepository.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
44

55
using System;
6+
using System.Collections.Concurrent;
67
using System.Collections.Generic;
78
using System.Linq;
89
using System.Reflection;
@@ -44,7 +45,7 @@ public class JavascriptObjectRepository : IJavascriptObjectRepository
4445
/// this is done to speed up finding the object in O(1) time
4546
/// instead of traversing the JavaScriptRootObject tree.
4647
/// </summary>
47-
private readonly Dictionary<long, JavascriptObject> objects = new Dictionary<long, JavascriptObject>();
48+
private readonly ConcurrentDictionary<long, JavascriptObject> objects = new ConcurrentDictionary<long, JavascriptObject>();
4849

4950
/// <summary>
5051
/// Has the browser this repository is associated with been initilized (set in OnAfterCreated)
@@ -195,7 +196,8 @@ public bool UnRegister(string name)
195196
{
196197
if (string.Equals(kvp.Value.Name, name, StringComparison.OrdinalIgnoreCase))
197198
{
198-
objects.Remove(kvp.Key);
199+
JavascriptObject obj;
200+
objects.TryRemove(kvp.Key, out obj);
199201

200202
return true;
201203
}

0 commit comments

Comments
 (0)