/// <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 ); }
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 WaitForAnyCounterChangeWhileNotPredecate(Func <int, bool> predecate) { _totalCounter.WaitForCounterChangeWhileNotPredecate(predecate); }