private void WorkingThreadStart(object sender, EventArgs args) { try { while (!MustBeStopped) { // Waits for new items _counter.WaitForCounterChangeWhileNotPredecate(count => count > 0); while (true) { // dequeuing queue bool shouldProceed = _items.TryDequeue(out var dequeuedItem); if (!shouldProceed) { break; } try { _actionInBackThread(dequeuedItem); } catch { continue; } finally { _counter.DecrementCount(); } } } } catch { //swallow all exceptions } finally { _endEvent.Set(); } }
public void DecrementCount(TKey key) { lock (_syncIncDec) { GetCounter(key).DecrementCount(); _totalCounter.DecrementCount(); } }
/// <summary> /// Adds async operations in queue /// </summary> /// <param name="asyncAction">Action that runs async</param> /// <param name="priority">Queue priority</param> /// <param name="key">Key-address</param> /// <returns>Id of queue item</returns> public Guid AddWork(Action <Action> asyncAction, int priority, TAddressKey key) { var id = _asyncActionQueueWorker.AddWork ( key, itemsReleaser => asyncAction(() => { itemsReleaser.ReportSomeAddressedItemIsFree(key); _totalFlowCounter.DecrementCount(); _debugLogger.Log("_totalFlowCounter.Count = " + _totalFlowCounter.Count); }), priority ); return(id); }
/// <summary> /// Calls by client and notifies starter about async operation is complete /// </summary> public void NotifyStarterAboutQueuedOperationComplete() { _flowCounter.DecrementCount(); _debugLogger.Log("_flowCounter.Count = " + _flowCounter.Count, new StackTrace()); }