public void HandleEnqueued() { while (true) { Action Action; lock (Tasks) { if (Tasks.Count == 0) break; Action = Tasks.Dequeue(); } Action(); } }