public void TestTaskSchedulerWork() { using (StaticThreadPool testInst = new StaticThreadPool(4, -1, "name", false, new StaticThreadPoolOptions() { UseOwnTaskScheduler = true, UseOwnSyncContext = true })) { bool firstTaskInPool = false; bool secondTaskInPool = false; var task = testInst.RunAsTask(() => { firstTaskInPool = testInst.IsThreadPoolThread; }).ContinueWith(t => { secondTaskInPool = testInst.IsThreadPoolThread; }, testInst.TaskScheduler); task.Wait(); Assert.IsTrue(firstTaskInPool); Assert.IsTrue(secondTaskInPool); testInst.Dispose(); } }
public void TestRunAsTaskWork() { using (StaticThreadPool testInst = new StaticThreadPool(4, -1, "name", false, new StaticThreadPoolOptions() { UseOwnTaskScheduler = true, UseOwnSyncContext = true })) { int wasExecuted = 0; var task = testInst.RunAsTask(() => { Interlocked.Exchange(ref wasExecuted, 1); }); task.Wait(); Assert.AreEqual(1, Volatile.Read(ref wasExecuted)); } }
public void TestRunAsTaskWithParamNoTaskSchedWork() { using (StaticThreadPool testInst = new StaticThreadPool(4, -1, "name", false, new StaticThreadPoolOptions() { UseOwnTaskScheduler = false, UseOwnSyncContext = false })) { int wasExecuted = 0; int paramValue = 0; var task = testInst.RunAsTask((p) => { Interlocked.Exchange(ref paramValue, p); Interlocked.Exchange(ref wasExecuted, 1); }, 100); task.Wait(); Assert.AreEqual(1, Volatile.Read(ref wasExecuted)); Assert.AreEqual(100, Volatile.Read(ref paramValue)); } }