Beispiel #1
0
        public async Task PoolThreadIsWorker()
        {
            var defautPool = DedicatedThreadPoolPipeScheduler.Default;

            using (var newPool = new DedicatedThreadPoolPipeScheduler())
            {
                var tcs = new TaskCompletionSource <bool>();
                defautPool.Schedule(
                    _ => tcs.SetResult(DedicatedThreadPoolPipeScheduler.IsWorker()), null);
                Assert.True(await tcs.Task);

                tcs = new TaskCompletionSource <bool>();
                newPool.Schedule(
                    _ => tcs.SetResult(DedicatedThreadPoolPipeScheduler.IsWorker()), null);
                Assert.True(await tcs.Task);

                tcs = new TaskCompletionSource <bool>();
                defautPool.Schedule(
                    _ => tcs.SetResult(DedicatedThreadPoolPipeScheduler.IsWorker(defautPool)), null);
                Assert.True(await tcs.Task);

                tcs = new TaskCompletionSource <bool>();
                newPool.Schedule(
                    _ => tcs.SetResult(DedicatedThreadPoolPipeScheduler.IsWorker(defautPool)), null);
                Assert.False(await tcs.Task);

                tcs = new TaskCompletionSource <bool>();
                defautPool.Schedule(
                    _ => tcs.SetResult(DedicatedThreadPoolPipeScheduler.IsWorker(newPool)), null);
                Assert.False(await tcs.Task);

                tcs = new TaskCompletionSource <bool>();
                newPool.Schedule(
                    _ => tcs.SetResult(DedicatedThreadPoolPipeScheduler.IsWorker(newPool)), null);
                Assert.True(await tcs.Task);
            }
        }
Beispiel #2
0
 public void TestRunnerIsNotWorker()
 {
     Assert.False(DedicatedThreadPoolPipeScheduler.IsWorker());
     Assert.False(DedicatedThreadPoolPipeScheduler.IsWorker(DedicatedThreadPoolPipeScheduler.Default));
 }