public void ProcessJobs() { if (Thread.CurrentThread != _thread) { throw new InvalidOperationException("Unable to process jobs on a different thread."); } lock (_queue) { // Process all jobs while (_queue.Count > 0) { var action = _queue.Dequeue(); lock (action) { action(); // ThreadMonitor.PulseAll(action); } } } }
/// <summary> /// Wake up all threads waiting on the monitor. /// </summary> public static void PulseAll(Object obj) { Monitor monitor = GetMonitorFromSyncBlock(obj); monitor.PulseAll(); }
/// <summary> /// Notifies all waiting threads of a change in the object's state. /// </summary> public virtual void PulseAll() => SystemMonitor.PulseAll(this.SyncObject);
public void PulseAll() { lock (this) Monitor.PulseAll(this); }