예제 #1
0
파일: Tests1.cs 프로젝트: CriDos/AsTask
        public async Task TestToStaticThreadPool()
        {
            await AsTask.ToStaticThreadPool();

            Console.WriteLine(AsTask.WhereAmI());
            Assert.True(AsTask.IsStaticThreadPool(), "This is not the StaticThreadPool!");
        }
예제 #2
0
파일: Tests1.cs 프로젝트: CriDos/AsTask
        public async Task TestDelayAwaiterStaticThreadPool()
        {
            await AsTask.ToStaticThreadPool();

            var stopwatch = Stopwatch.StartNew();
            await Task.Delay(100);

            stopwatch.Stop();
            Assert.True(AsTask.IsStaticThreadPool(), $"This is not the StaticThreadPool: {AsTask.WhereAmI()}");
            Console.WriteLine($"{nameof(stopwatch)} {stopwatch.ElapsedMilliseconds}ms == {AsTask.GetCurrentContextType()} awaiter 100ms");
            Assert.True(stopwatch.ElapsedMilliseconds >= 80 && stopwatch.ElapsedMilliseconds <= 150);
        }
예제 #3
0
파일: Tests1.cs 프로젝트: CriDos/AsTask
        public async Task TestMoreSwitching()
        {
            for (var i = 0; i < 1000; i++)
            {
                await TestSwitchingToContexts();
            }

            for (var i = 0; i < 1000; i++)
            {
                await AsTask.ToMainContext();

                Assert.True(AsTask.IsMainContext());
            }

            for (var i = 0; i < 1000; i++)
            {
                await AsTask.ToBackgroundContext();

                Assert.True(AsTask.IsBackgroundContext());
            }

            for (var i = 0; i < 1000; i++)
            {
                await AsTask.ToContext(_contextTests1Id);

                Assert.True(AsTask.IsThreadContext(_contextTests1Id));
            }

            for (var i = 0; i < 1000; i++)
            {
                await AsTask.ToStaticThreadPool();

                Assert.True(AsTask.IsStaticThreadPool());
            }

            for (var i = 0; i < 1000; i++)
            {
                await AsTask.ToDynamicThreadPool();

                Assert.True(AsTask.IsDynamicThreadPool());
            }
        }