public void Increment() { if (StopSignal) { throw new InvalidOperationException("Impossible to increase the counter"); } _counterBlocked.Increment(); if (StopSignal) { _counterBlocked.Decremenet(); throw new InvalidOperationException("Impossible to increase the counter"); } }
public async Task <object> Invoke(TData data, CancellationToken token) { try { var result = await _actionInvoker.Invoke(data, token); return(result); } finally { _counterBlocked.Decremenet(); } }
public async Task ExcecuteInvoker(IActionInvoker actionInvoker) { using (var tokenSource = new CancellationTokenSource()) { _counterBlocked.Increment(); try { #if DEBUG Trace.WriteLine(String.Format("start process count = {0}", _counterBlocked.Count)); #endif if (actionInvoker is IActionInvokerLifetime invokerTimeLimit) { tokenSource.CancelAfter(invokerTimeLimit.Lifetime); } else { tokenSource.CancelAfter(_timeLimit); } await ProcessMessage(actionInvoker, tokenSource.Token); } catch (Exception ex) { _workerHandler.HandleFault(ex); } finally { _counterBlocked.Decremenet(); _queueWorker.SetWorkerEnd(); } } #if DEBUG Trace.WriteLine(String.Format("stop process, quantity left = {0}", _counterBlocked.Count)); #endif }