QueueUserWorkItem() public method

public QueueUserWorkItem ( WaitCallback worker ) : void
worker WaitCallback
return void
コード例 #1
0
        public void TestAllTasksComplete()
        {
            ThreadPoolExecutor executor = new ThreadPoolExecutor();
            Assert.IsNotNull(executor);
            Assert.IsFalse(executor.IsShutdown);

            for(int i = 0; i < JOB_COUNT; ++i)
            {
                executor.QueueUserWorkItem(TaskThatCountsDown);
            }

            Assert.IsTrue(this.doneLatch.await(TimeSpan.FromMilliseconds(30 * 1000)));

            executor.Shutdown();
            Assert.IsTrue(executor.IsShutdown);
        }
コード例 #2
0
        public void TestThatShutdownPurgesTasks()
        {
            ThreadPoolExecutor executor = new ThreadPoolExecutor();
            Assert.IsNotNull(executor);
            Assert.IsFalse(executor.IsShutdown);

            executor.QueueUserWorkItem(TaskThatSleeps);

            for(int i = 0; i < JOB_COUNT; ++i)
            {
                executor.QueueUserWorkItem(TaskThatIncrementsCount);
            }

            Thread.Sleep(100);

            executor.Shutdown();
            Assert.AreEqual(0, count);
            Assert.IsTrue(executor.IsShutdown);
        }
コード例 #3
0
        public void TestTaskParamIsPropagated()
        {
            ThreadPoolExecutor executor = new ThreadPoolExecutor();
            Assert.IsNotNull(executor);
            Assert.IsFalse(executor.IsShutdown);

            executor.QueueUserWorkItem(TaskThatValidatesTheArg, new DummyClass(10));

            this.complete.WaitOne();
            Assert.IsTrue(this.waitingTaskCompleted);

            executor.Shutdown();
            Assert.IsTrue(executor.IsShutdown);
        }
コード例 #4
0
        public void TestSingleTaskExecuted()
        {
            ThreadPoolExecutor executor = new ThreadPoolExecutor();
            Assert.IsNotNull(executor);
            Assert.IsFalse(executor.IsShutdown);

            executor.QueueUserWorkItem(TaskThatSignalsWhenItsComplete);

            this.complete.WaitOne();
            Assert.IsTrue(this.waitingTaskCompleted);

            executor.Shutdown();
            Assert.IsTrue(executor.IsShutdown);
        }