public void CancelInProgressWorkItemSoftWithAbortOnWorkItemCancel() { bool abortFailed = false; ManualResetEvent waitToStart = new ManualResetEvent(false); ManualResetEvent waitToCancel = new ManualResetEvent(false); STP stp = new STP(); IWorkItemResult wir = stp.QueueWorkItem( state => { waitToStart.Set(); waitToCancel.WaitOne(); STP.AbortOnWorkItemCancel(); abortFailed = true; return(null); }); waitToStart.WaitOne(); wir.Cancel(false); waitToCancel.Set(); stp.WaitForIdle(); Assert.IsTrue(wir.IsCanceled); Assert.IsFalse(abortFailed); stp.Shutdown(); }
public void TimeoutInProgressWorkItemSoftWithAbortOnWorkItemCancel() { bool abortFailed = false; ManualResetEvent waitToStart = new ManualResetEvent(false); ManualResetEvent waitToComplete = new ManualResetEvent(false); STP stp = new STP(); IWorkItemResult wir = stp.QueueWorkItem( new WorkItemInfo() { Timeout = 500 }, state => { waitToStart.Set(); Thread.Sleep(1000); STP.AbortOnWorkItemCancel(); abortFailed = true; return(null); }); waitToStart.WaitOne(); stp.WaitForIdle(); Assert.IsTrue(wir.IsCanceled); Assert.IsFalse(abortFailed); stp.Shutdown(); }