diff --git a/C#/AutoHotInterception/InterceptionWrapper.cs b/C#/AutoHotInterception/InterceptionWrapper.cs index 0962a75..6605da7 100644 --- a/C#/AutoHotInterception/InterceptionWrapper.cs +++ b/C#/AutoHotInterception/InterceptionWrapper.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; using System.Linq; @@ -16,8 +17,8 @@ public class InterceptionWrapper private readonly bool _filterState = false; - private readonly Dictionary> _mappings = new Dictionary>(); - private readonly Dictionary _contextCallbacks = new Dictionary(); + private readonly ConcurrentDictionary> _mappings = new ConcurrentDictionary>(); + private readonly ConcurrentDictionary _contextCallbacks = new ConcurrentDictionary(); // If a the ID of a device exists as a key in this Dictionary, then that device is filtered. // Used by IsMonitoredKeyboard private readonly Dictionary _filteredDevices = new Dictionary(); @@ -62,10 +63,10 @@ public class InterceptionWrapper if (id == 0) return false; if (!_mappings.ContainsKey(id)) { - _mappings.Add(id, new Dictionary()); + _mappings.TryAdd(id, new ConcurrentDictionary()); } - _mappings[id].Add(code, new Mapping() { block = block, callback = callback }); + _mappings[id].TryAdd(code, new Mapping() { block = block, callback = callback }); _filteredDevices[id] = true; SetFilterState(true);