public void Stop_Tasks_ShutdownCalled() { var pipeline = ""; var target = new TplTaskExecutor { Timeout = TimeSpan.FromMilliseconds(1000) }; target.Add(() => { Thread.Sleep(500); pipeline += "1"; }); target.Add(() => { Thread.Sleep(500); pipeline += "2"; }); target.Add(() => { Thread.Sleep(500); pipeline += "3"; }); Parallel.Invoke( () => target.Start(), () => { Thread.Sleep(100); target.Stop(); }); Assert.IsFalse(target.IsRunning); }
public void Stop_ManyTasks_StopAll() { var pipeline = ""; var target = new TplTaskExecutor(); target.Timeout = TimeSpan.FromMilliseconds(1000); target.Add(() => { Thread.Sleep(5); pipeline += "1"; }); target.Add(() => { Thread.Sleep(5); pipeline += "2"; }); target.Add(() => { Thread.Sleep(5); pipeline += "3"; }); Parallel.Invoke( () => Assert.IsTrue(target.Start()), () => { Thread.Sleep(100); target.Stop(); }); }