public SingleThreadPriorityAsyncStarter(string name, ThreadPriority threadPriority, bool markThreadAsBackground, ApartmentState?apartmentState, ILoggerWithStackTrace debugLogger, int maxFlow, int queuesCount, bool isWaitAllTasksCompleteNeededOnStop)
        {
            _name        = name;
            _debugLogger = debugLogger ?? throw new ArgumentNullException(nameof(debugLogger));
            _maxFlow     = maxFlow;
            _isWaitAllTasksCompleteNeededOnStop = isWaitAllTasksCompleteNeededOnStop;

            _flowCounter            = new WaitableCounter();
            _asyncActionQueueWorker = new SingleThreadedRelayMultiQueueWorker <Action>(_name, a => a(), threadPriority, markThreadAsBackground, apartmentState, debugLogger, queuesCount);
        }
        public SingleThreadPriorityAddressedAsyncStarterExceptionless(
            string name,
            ThreadPriority threadPriority, bool markThreadAsBackground, ApartmentState?apartmentState, ILogger debugLogger,
            uint maxTotalFlow, uint maxFlowPerAddress, int priorityGradation, bool isWaitAllTasksCompleteNeededOnStop)
        {
            _name        = name;
            _debugLogger = debugLogger ?? throw new ArgumentNullException(nameof(debugLogger));
            _isWaitAllTasksCompleteNeededOnStop = isWaitAllTasksCompleteNeededOnStop;

            _totalFlowCounter       = new WaitableCounter(0);
            _asyncActionQueueWorker = new SingleThreadedRelayAddressedMultiQueueWorkerExceptionless <TAddressKey, Action <IItemsReleaser <TAddressKey> > >
                                      (
                _name, RunActionWithAsyncTailBack, threadPriority, markThreadAsBackground, apartmentState, debugLogger,
                priorityGradation,
                maxFlowPerAddress,
                maxTotalFlow);
        }
예제 #3
0
        public BackgroundQueueWorker(Action <TItem> actionInBackThread)
        {
            _sync     = new object();
            _endEvent = new ManualResetEvent(false);

            _items = new ConcurrentQueue <TItem>();
            _actionInBackThread = actionInBackThread;

            _counter = new WaitableCounter();

            _isRunning     = true;
            _mustBeStopped = false;

            _workThread = new BackgroundWorker {
                WorkerReportsProgress = true
            };
            _workThread.DoWork += WorkingThreadStart;
            _workThread.RunWorkerAsync();
            _workThread.ProgressChanged += (sender, args) => ((Action)args.UserState).Invoke();             // if throws it will be in initial thread
        }