18 using System.Threading;
19 using System.Collections.Generic;
28 private readonly Dictionary<string, string> _currentStrings =
new ();
36 public void Execute(
string key,
bool singleExecution, Action action)
38 ExecuteImplementation(key, singleExecution, action);
49 ExecuteImplementation(key, singleExecution:
false, () =>
56 private void ExecuteImplementation(
string key,
bool singleExecution, Action action)
62 bool lockTaken =
false;
64 lock (_currentStrings)
66 if(!_currentStrings.TryGetValue(key, out existingKey))
68 _currentStrings[key] = existingKey = key;
74 lockTaken = Monitor.TryEnter(existingKey);
86 lock (_currentStrings)
89 _currentStrings.Remove(key);
98 Monitor.Exit(existingKey);
105 if (!singleExecution)