Beispiel #1
0
 public async Task LatchedTaskStops_Runs_On_Shutdown()
 {
     using (var runner = new BackgroundTaskRunner <IBackgroundTask>(new BackgroundTaskRunnerOptions(), _logger))
     {
         var task = new MyLatchedTask(200, true);
         runner.Add(task);
         Assert.IsTrue(runner.IsRunning);
         Thread.Sleep(5000);
         Assert.IsTrue(runner.IsRunning); // still waiting for the task to release
         Assert.IsFalse(task.HasRun);
         runner.Shutdown(false, false);   // -force, -wait
         await runner.StoppedAwaitable;   // wait for the entire runner operation to complete
         Assert.IsTrue(task.HasRun);
     }
 }
Beispiel #2
0
        public async Task CancelLatchedTask()
        {
            using (var runner = new BackgroundTaskRunner <IBackgroundTask>(new BackgroundTaskRunnerOptions(), _logger))
            {
                var task = new MyLatchedTask(4000, false);
                runner.Add(task);
                Assert.IsTrue(runner.IsRunning);
                await Task.Delay(1000); // ensure the task *has* started else cannot cancel

                runner.CancelCurrentBackgroundTask();

                await runner.StoppedAwaitable; // wait for the entire runner operation to complete
                Assert.IsFalse(task.HasRun);
            }
        }
 public async void LatchedTaskRuns()
 {
     using (var runner = new BackgroundTaskRunner <IBackgroundTask>(new BackgroundTaskRunnerOptions(), _logger))
     {
         var task = new MyLatchedTask(200, false);
         runner.Add(task);
         Assert.IsTrue(runner.IsRunning);
         Thread.Sleep(1000);
         Assert.IsTrue(runner.IsRunning); // still waiting for the task to release
         Assert.IsFalse(task.HasRun);
         task.Release();
         await runner.CurrentThreadingTask; // wait for current task to complete
         Assert.IsTrue(task.HasRun);
         await runner.StoppedAwaitable;     // wait for the entire runner operation to complete
     }
 }