From a6701f3e7dee7cff08e9c7f9070580cfe6836dc2 Mon Sep 17 00:00:00 2001 From: evilC Date: Thu, 22 Mar 2018 20:46:31 +0000 Subject: [PATCH] Change to ConcurrentDictionary --- C#/AutoHotInterception/InterceptionWrapper.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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);