private void Work() { try { SubThreadChanger = ThreadChanger.GetSubThreadChanger(); while (true) { QueueTask task = null; lock (_locker) { if (_tasks.Count > 0) { task = _tasks.Dequeue(); if (task == null) // empty task = signal for stop { return; } } } if (task != null) { DoTask(task); } else { // Queue is empty, waiting for a new task _wh.WaitOne(); } } } catch (Exception ex) { Logger.Log(LogLevel.Warn, ex, "An abnormal exception occurs in a TaskQueue that has not been catched properly"); } }
public ISubThreadChanger GetSubThreadChanger() => ThreadChanger.GetSubThreadChanger();