Beispiel #1
0
 public WorkerManager(ConsoleWriter consoleWriter, ConsoleWorker newWorker)
 {
     UniqueID = Guid.NewGuid();
     State    = WorkerStateEnum.Stopped;
     console  = consoleWriter;
     worker   = newWorker;
     watch    = new Stopwatch();
 }
Beispiel #2
0
        public void Resume()
        {
            if (State != WorkerStateEnum.Suspended)
            {
                throw new InvalidOperationException("Attempted to resume a non suspended worker");
            }

            State = WorkerStateEnum.Running;
        }
Beispiel #3
0
        public void Suspend()
        {
            if (State != WorkerStateEnum.Running)
            {
                throw new InvalidOperationException("Attempted to suspend a non running worker");
            }

            State = WorkerStateEnum.Suspended;
        }
Beispiel #4
0
        public void Start()
        {
            if (State == WorkerStateEnum.Running)
            {
                throw new InvalidOperationException("Worker already started");
            }

            State = WorkerStateEnum.Running;
            worker.OnStart(console);
            ExecuteCicle();
        }
Beispiel #5
0
        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();
        }