コード例 #1
0
        /// <summary>
        /// Adds a new worker.
        /// </summary>
        private void AddWorker()
        {
            var worker = _workerFactory.Create();

            _workers.Add(worker);
            worker.SystemException += RaiseSystemException;
            worker.UserException   += RaiseUserException;
        }
コード例 #2
0
        public WorkingLine(EventLoop eventLoop, string queueTag, IWorkerFactory factory, int worker = 1, ThreadPriority threadPriority = ThreadPriority.Normal)
        {
            QueueTag       = queueTag ?? throw new ArgumentNullException(nameof(queueTag));
            WorkerFactory  = factory ?? throw new ArgumentNullException(nameof(factory));
            Worker         = Math.Max(1, Math.Min(MAX_WORKER, worker));
            ThreadPriority = threadPriority;
            _eventLoop     = eventLoop;

            for (int i = 0; i < worker; i++)
            {
                var thread = new WorkerThread(_queue, factory.Create(), $"{queueTag}_{i:0000}");
                _threadBusy[thread] = false;
                _threads.Add(thread);
                thread.BusyChanged  += WorkerThreadBusyChangedHandler;
                thread.TaskRejected += WorkerThreadTaskRejectedHandler;
                thread.WorkerError  += WorkerThreadErrorHandler;
                thread.TaskBegin    += WorkerThreadTaskBeginHandler;
                thread.TaskEnd      += WorkerThreadTaskEndHandler;
            }
        }