コード例 #1
0
        /// <summary> Method executed in parallel </summary>
        /// <param name="exceptionHandler"> Method which will be called in case of any thread raise an exception </param>
        public void Execute(Action <Exception> exceptionHandler)
        {
            Guard.NotNull(exceptionHandler, $"{nameof(exceptionHandler)}");

            try
            {
                while (_taskQueue.NotEmpty())
                {
                    _taskQueue.TryDequeue(out var task);
                    if (task == null)
                    {
                        return;
                    }
                    _taskProcessLogic.ProcessTask(task);
                    TaskSequenceNumber++;
                    ResetEvent.Set();
                }
            }
            catch (ThreadInterruptedException ex)
            {
                Log.Information($"Exception thrown {ex}");
            }
            catch (Exception ex)
            {
                Log.Information($"Exception thrown {ex}");
                exceptionHandler?.Invoke(ex);
            }
        }