Beispiel #1
0
        public WorkerToken StartDedicatedWorker()
        {
            var context = new WorkerContext(_maxQueuedMessages, _log);
            var worker  = new MessageHandlerWorker(context, "AcquaintanceDW");

            worker.Start();
            bool ok       = _dedicatedWorkers.TryAdd(worker.ThreadId, worker);
            int  threadId = ok ? worker.ThreadId : 0;

            return(new WorkerToken(this, threadId));
        }
Beispiel #2
0
        private IWorkerContext InitializeFreeWorkers(int numFreeWorkers, List <MessageHandlerWorker> freeWorkers)
        {
            if (numFreeWorkers <= 0)
            {
                return(null);
            }

            var freeWorkerContext = new WorkerContext(_maxQueuedMessages, _log);

            for (int i = 0; i < numFreeWorkers; i++)
            {
                var thread = new MessageHandlerWorker(freeWorkerContext, $"AcquaintanceFW{i}");
                freeWorkers.Add(thread);
                thread.Start();
            }
            return(freeWorkerContext);
        }