17 using System.Collections.Concurrent;
18 using System.Threading;
30 private readonly BlockingCollection<Action> _blockingCollection;
31 private readonly CancellationTokenSource _threadCancellationTokenSource;
32 private readonly Thread _workerThread;
50 _threadCancellationTokenSource =
new CancellationTokenSource();
52 _blockingCollection =
new BlockingCollection<Action>();
53 _workerThread =
new Thread(() =>
57 foreach (var action
in _blockingCollection.GetConsumingEnumerable(_threadCancellationTokenSource.Token))
59 FinishedWorkItem.Reset();
64 catch (Exception exception)
66 Log.
Error(exception,
"WorkerThread(): exception thrown when running task");
71 catch (OperationCanceledException)
78 Name =
"Isolator Thread",
79 Priority = ThreadPriority.Highest
81 _workerThread.Start();
88 public void Add(Action action)
90 _blockingCollection.Add(action);
102 _blockingCollection.CompleteAdding();
103 _workerThread.StopSafely(TimeSpan.FromMilliseconds(50), _threadCancellationTokenSource);
104 _threadCancellationTokenSource.DisposeSafely();
106 catch (Exception exception)