public override void OnStart(dynamic parameters) { string worker = parameters as string; _WorkerArray = string.IsNullOrEmpty(worker) ? Worker.All : new WorkerArray(Worker.Get(worker)); _WorkerArray.Start(onlyAutoStart: string.IsNullOrEmpty(worker)); }
// --------------- public Worker(WorkerArray workerArray, string name, ThreadPriority priority) { m_workerArray = workerArray; m_thread = new Thread(WorkerLoop); HasNoWork = new ManualResetEvent(false); Gate = new AutoResetEvent(false); m_thread.Name = name; m_thread.IsBackground = true; m_thread.Priority = priority; m_thread.CurrentCulture = CultureInfo.InvariantCulture; m_thread.CurrentUICulture = CultureInfo.InvariantCulture; m_thread.Start(null); }
/// <summary> /// Initialize all worker arrays. /// </summary> /// <param name="threadCount">Each array of workers will contain number of threads = threadCount.</param> private void InitializeWorkerArrays(int threadCount) { // determine how many arrays from the mapping int maxIndex = 0; foreach (int mappingIndex in m_mappingPriorityToWorker) maxIndex = mappingIndex > maxIndex ? mappingIndex : maxIndex; // initialize arrays m_workerArrays = new WorkerArray[maxIndex + 1]; m_hasNoWork = new WaitHandle[(maxIndex + 1) * threadCount]; int hasNoWorkIterator = 0; for (int i = 0; i <= maxIndex; i++) { m_workerArrays[i] = new WorkerArray(this, i, threadCount, m_mappingWorkerToThreadPriority[i]); for (int workerIndex = 0; workerIndex < threadCount; workerIndex++) // initialize workers inside the array { m_hasNoWork[hasNoWorkIterator++] = m_workerArrays[i].Workers[workerIndex].HasNoWork; } } }
/// <summary> /// Initialize all worker arrays. /// </summary> /// <param name="threadCount">Each array of workers will contain number of threads = threadCount.</param> private void InitializeWorkerArrays(int threadCount) { // determine how many arrays from the mapping int maxIndex = 0; foreach (int mappingIndex in m_mappingPriorityToWorker) { maxIndex = mappingIndex > maxIndex ? mappingIndex : maxIndex; } // initialize arrays m_workerArrays = new WorkerArray[maxIndex + 1]; m_hasNoWork = new WaitHandle[(maxIndex + 1) * threadCount]; int hasNoWorkIterator = 0; for (int i = 0; i <= maxIndex; i++) { m_workerArrays[i] = new WorkerArray(this, i, threadCount, m_mappingWorkerToThreadPriority[i]); for (int workerIndex = 0; workerIndex < threadCount; workerIndex++) // initialize workers inside the array { m_hasNoWork[hasNoWorkIterator++] = m_workerArrays[i].Workers[workerIndex].HasNoWork; } } }
public void Start(string worker = null) { _WorkerArray = string.IsNullOrEmpty(worker) ? Worker.All : new WorkerArray(Worker.Get(worker)); _WorkerArray.Start(onlyAutoStart: string.IsNullOrEmpty(worker)); AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload; }