public Worker( Queue <IWorkerTask> taskQueue, ref object syncRoot, WorkerProgress progress, ILog log, DisposingOptions disposingOptions) { this.taskQueue = taskQueue; this.syncRoot = syncRoot; this.progress = progress; this.disposingOptions = disposingOptions; thread = new Thread(WorkerRoutine) { IsBackground = true }; this.log = log.WithPrefix($"[Thread {thread.ManagedThreadId}]"); thread.Start(); }
public WorkersPool(int workersCount, ILog log, DisposingOptions disposingOptions = null) { if (workersCount <= 0) { throw new ArgumentException("Workers count can't be negative or zero number", nameof(workersCount)); } if (log == null) { throw new ArgumentNullException(nameof(log)); } disposingOptions = disposingOptions ?? DisposingOptions.Default; this.log = log.WithPrefix($"[{nameof(WorkersPool)}]"); taskQueue = new Queue <IWorkerTask>(workersCount); progress = new WorkerProgress(); workers = new List <Worker>(workersCount); for (var i = 0; i < workersCount; i++) { workers.Add(new Worker(taskQueue, ref syncObject, progress, log, disposingOptions)); } }