public PoolWorker(WorkerQueue work, DedicatedThreadPool pool, bool errorRecovery) { _work = work; _pool = pool; _workQueue = _work.WorkQueue; _work.ReplacePoolWorker(this, errorRecovery); _thread = new Thread(() => { CurrentWorker = this; foreach (var action in _workQueue.GetConsumingEnumerable()) { try { //bail if shutdown has been requested if (_pool.ShutdownRequested) { return; } action(); } catch (Exception ex) { Failover(true); return; } } }) { IsBackground = _pool.Settings.ThreadType == ThreadType.Background }; _thread.Start(); }
public PoolWorker(WorkerQueue work, DedicatedThreadPool pool, bool errorRecovery, int workerNumber) { _work = work; _pool = pool; _workerNumber = workerNumber; _workQueue = _work.WorkQueue; _work.ReplacePoolWorker(this, errorRecovery); _thread = new Thread(() => { Thread.CurrentThread.Name = string.Format("{0}_{1}", pool.Settings.Name, _workerNumber); CurrentWorker = this; foreach (var action in _workQueue.GetConsumingEnumerable()) { try { //bail if shutdown has been requested if (_pool.ShutdownRequested) { return; } action(); } catch (Exception) { Failover(true); return; } } }) { IsBackground = _pool.Settings.ThreadType == ThreadType.Background }; if (_pool.Settings.ApartmentState != ApartmentState.Unknown) { _thread.SetApartmentState(_pool.Settings.ApartmentState); } _thread.Start(); }
public PoolWorker(WorkerQueue work, DedicatedThreadPool pool, bool errorRecovery) { _work = work; _pool = pool; _workQueue = _work.WorkQueue; _work.ReplacePoolWorker(this, errorRecovery); _thread = new Thread(() => { CurrentWorker = this; foreach (var action in _workQueue.GetConsumingEnumerable()) { try { //bail if shutdown has been requested if (_pool.ShutdownRequested) return; action(); } catch (Exception ex) { Failover(true); return; } } }) { IsBackground = _pool.Settings.ThreadType == ThreadType.Background }; _thread.Start(); }
public PoolWorker(WorkerQueue work, DedicatedThreadPool pool, bool errorRecovery, int workerNumber) { _work = work; _pool = pool; _workerNumber = workerNumber; _workQueue = _work.WorkQueue; _work.ReplacePoolWorker(this, errorRecovery); _thread = new Thread(() => { Thread.CurrentThread.Name = string.Format("{0}_{1}", pool.Settings.Name, _workerNumber); CurrentWorker = this; foreach (var action in _workQueue.GetConsumingEnumerable()) { try { //bail if shutdown has been requested if (_pool.ShutdownRequested) return; action(); } catch (Exception) { Failover(true); return; } } }) { IsBackground = _pool.Settings.ThreadType == ThreadType.Background }; if (_pool.Settings.ApartmentState != ApartmentState.Unknown) _thread.SetApartmentState(_pool.Settings.ApartmentState); _thread.Start(); }