예제 #1
0
        public void TestTaskThreadPoolWorkItemExecute()
        {
            int wasExecuted = 0;

            var item = new TaskThreadPoolWorkItem(() =>
            {
                Interlocked.Exchange(ref wasExecuted, 1);
            });

            item.Run(false, true);

            Assert.AreEqual(1, wasExecuted);
            Assert.IsTrue(item.Task.IsCompleted);
        }
예제 #2
0
        public void TestTaskThreadPoolWorkItemWithParamExecute()
        {
            int wasExecuted = 0;
            int stateVal    = 0;

            var item = new TaskThreadPoolWorkItem <int>((state) =>
            {
                stateVal = state;
                Interlocked.Exchange(ref wasExecuted, 1);
            }, 100);

            item.Run(false, true);

            Assert.AreEqual(1, wasExecuted);
            Assert.AreEqual(100, stateVal);
            Assert.IsTrue(item.Task.IsCompleted);
        }