public void CancelInQueueWorkItem()
        {
            Assert.ThrowsException <WorkItemCancelException>(() =>
            {
                STPStartInfo stpStartInfo   = new STPStartInfo();
                stpStartInfo.StartSuspended = true;

                bool hasRun = false;

                STP stp             = new STP(stpStartInfo);
                IWorkItemResult wir = stp.QueueWorkItem(
                    new WorkItemInfo()
                {
                    Timeout = 500
                },
                    state =>
                {
                    hasRun = true;
                    return(null);
                });

                Assert.IsFalse(wir.IsCanceled);

                Thread.Sleep(2000);

                Assert.IsTrue(wir.IsCanceled);

                stp.Start();
                stp.WaitForIdle();

                Assert.IsFalse(hasRun);

                try
                {
                    wir.GetResult();
                }
                finally
                {
                    stp.Shutdown();
                }
            });
        }
Esempio n. 2
0
        // Can't run this test, StackOverflowException crashes the application and can't be catched and ignored
        //[TestMethod]
        public void NotTestThreadsMaxStackSize()
        {
            STPStartInfo stpStartInfo = new STPStartInfo()
            {
                MaxStackSize = 64 * 1024,
            };

            STP stp = new STP(stpStartInfo);

            stp.Start();

            IWorkItemResult <bool> wir = stp.QueueWorkItem(() => AllocateBufferOnStack(10 * 1024));

            bool result = wir.GetResult();

            Assert.IsTrue(result);

            wir = stp.QueueWorkItem(() => AllocateBufferOnStack(1000 * 1024));

            result = wir.GetResult();
            Assert.IsFalse(result);
        }