public WorkerManager(ConsoleWriter consoleWriter, ConsoleWorker newWorker) { UniqueID = Guid.NewGuid(); State = WorkerStateEnum.Stopped; console = consoleWriter; worker = newWorker; watch = new Stopwatch(); }
public void Resume() { if (State != WorkerStateEnum.Suspended) { throw new InvalidOperationException("Attempted to resume a non suspended worker"); } State = WorkerStateEnum.Running; }
public void Suspend() { if (State != WorkerStateEnum.Running) { throw new InvalidOperationException("Attempted to suspend a non running worker"); } State = WorkerStateEnum.Suspended; }
public void Start() { if (State == WorkerStateEnum.Running) { throw new InvalidOperationException("Worker already started"); } State = WorkerStateEnum.Running; worker.OnStart(console); ExecuteCicle(); }
public async Task StopAsync() { if (State == WorkerStateEnum.Stopped) { return; } State = WorkerStateEnum.Stopped; if (acutalTask == null) { return; } if (acutalTask.Status.HasFlag(TaskStatus.Running) || acutalTask.Status.HasFlag(TaskStatus.RanToCompletion)) { await acutalTask; } worker.OnStop(console, TimeSpan.FromMilliseconds(watch.ElapsedMilliseconds)); watch.Stop(); }