public override void Start() { lock (this.pool) { if (this.state == RunState.Created || this.state == RunState.Stopped) { this.state = RunState.Starting; try { this.runner.Eventer.Token = this.pool.CurrentToken; TaskPoolRunner r = null; do { r = this.pool.Next(); if (r != null) { r.Run(); //scavenging pool will make this a never-ending loop across all threads } }while (r == null); this.state = RunState.Running; } catch { this.state = RunState.FailedStarting; } } } }
private volatile int activeWaiters = 0; //how many calls to Next() are waiting public TaskPool(Action toRun, TaskPoolOptions options) { MethodContract.NotNull(toRun, nameof(toRun)); this.options = new TaskPoolOptions(); if (options != null) { this.options.MaxWaitingRequests = options.MaxWaitingRequests; this.options.MaxActiveWorkers = options.MaxActiveWorkers; this.options.Timeout = options.Timeout; } this.activeWorkers = 0; this.runner = new TaskPoolRunner(this, toRun, this.options.Timeout); this.Reset(); }
/// <summary> /// The work function to provide the pool as the action to run /// </summary> internal void Run() { this.run(); try { TaskPoolRunner r = null; do { r = this.pool.Next(); if (r != null) { r.Run(); //remember this is an async call } }while (r == null); } catch { } }
public override void Start() { lock (this.listenerPool) { if (this.state == RunState.Created || this.state == RunState.Stopped) { this.state = RunState.Starting; try { this.token = this.handlerPool.CurrentToken; this.eventer.Token = this.handlerPool.CurrentToken; this.listenerPool.Next().Run(); //scavenging pool will make this a never-ending loop across all threads //spin up all the handlers TaskPoolRunner r = null; for (int i = 0; i < this.handlerThreads; i++) { do { r = this.handlerPool.Next(); if (r != null) { r.Run(); //scavenging pool will make this a never-ending loop across all threads } }while (r == null); r = null; } this.state = RunState.Running; } catch { this.state = RunState.FailedStarting; } } } }