Exemplo n.º 1
0
        public void TimeoutInProgressWorkItemSoftWithAbortOnWorkItemCancel()
        {
            bool             abortFailed    = false;
            ManualResetEvent waitToStart    = new ManualResetEvent(false);
            ManualResetEvent waitToComplete = new ManualResetEvent(false);

            SmartThreadPool stp = new SmartThreadPool();
            IWorkItemResult wir = stp.QueueWorkItem(
                new WorkItemInfo()
            {
                Timeout = 500
            },
                state =>
            {
                waitToStart.Set();
                Thread.Sleep(1000);
                SmartThreadPool.AbortOnWorkItemCancel();
                abortFailed = true;
                return(null);
            });

            waitToStart.WaitOne();

            stp.WaitForIdle();

            Assert.IsTrue(wir.IsCanceled);
            Assert.IsFalse(abortFailed);
            stp.Shutdown();
        }
Exemplo n.º 2
0
        public void CancelInProgressWorkItemSoftWithAbortOnWorkItemCancel()
        {
            bool             abortFailed  = false;
            ManualResetEvent waitToStart  = new ManualResetEvent(false);
            ManualResetEvent waitToCancel = new ManualResetEvent(false);

            SmartThreadPool stp = new SmartThreadPool();
            IWorkItemResult wir = stp.QueueWorkItem(
                state => {
                waitToStart.Set();
                waitToCancel.WaitOne();
                SmartThreadPool.AbortOnWorkItemCancel();
                abortFailed = true;
                return(null);
            });

            waitToStart.WaitOne();

            wir.Cancel(false);

            waitToCancel.Set();

            stp.WaitForIdle();

            Assert.IsTrue(wir.IsCanceled);
            Assert.IsFalse(abortFailed);

            stp.Shutdown();
        }