public void AddWork(TItem workItem) { if (!MustBeStopped) { _items.Enqueue(workItem); _counter.IncrementCount(); } else { throw new Exception("Cannot handle items any more, asyncWorker has been stopped or stopping now"); } }
public void IncrementCount(TKey key) { lock (_syncIncDec) { GetCounter(key).IncrementCount(); _totalCounter.IncrementCount(); } }
/// <summary> /// Runs ending of async operation giving queue items releaser to it /// </summary> /// <param name="asyncOperationBeginAction">Action that runs at the end of async operation</param> /// <param name="itemsReleaser">Items releaser</param> private void RunActionWithAsyncTailBack(Action <IItemsReleaser <TAddressKey> > asyncOperationBeginAction, IItemsReleaser <TAddressKey> itemsReleaser) { try { _totalFlowCounter.IncrementCount(); _debugLogger.Log("_totalFlowCounter.Count = " + _totalFlowCounter.Count); asyncOperationBeginAction(itemsReleaser); } catch (Exception ex) { _debugLogger.Log(ex); } }
/// <summary> /// Adds async operations in queue /// </summary> /// <param name="asyncAction">Action that runs async</param> /// <param name="queueNumber">Queue priority</param> public void AddWork(Action asyncAction, int queueNumber) { _asyncActionQueueWorker.AddWork ( () => { _flowCounter.WaitForCounterChangeWhileNotPredecate(curCount => curCount < _maxFlow); _flowCounter.IncrementCount(); _debugLogger.Log("_flowCounter.Count = " + _flowCounter.Count, new StackTrace()); asyncAction(); }, queueNumber ); }