private async void OnStart(object state) { while (true) { while (mQueue.TryDequeue(out IEventWork item)) { System.Threading.Interlocked.Decrement(ref mCount); using (item) { try { await item.Execute(); } catch (Exception e_) { OnError(e_, item); } } } lock (_workSync) { if (mQueue.IsEmpty) { try { Unused?.Invoke(); } catch { } _doingWork = false; return; } } } }