示例#1
0
        public async Task Run()
        {
            Diag.PrintContext("ENTER");
            await WorkWithoutCA();

            Diag.PrintContext("EXIT");
        }
示例#2
0
        private async Task DoWorkAsync(uint cycles)
        {
            Diag.PrintContext("ENTER");
            await BlockingWorkAsync(cycles).PrintContext();

            Diag.PrintContext("EXIT");
        }
示例#3
0
        private async Task DoWorkAsyncCA(uint cycles)
        {
            Diag.PrintContext("ENTER");
            await BlockingWorkAsyncCA(cycles).PrintContext().ConfigureAwait(false);

            Diag.PrintContext("EXIT");
        }
示例#4
0
        public async Task Run()
        {
            // regular async calls with no use of ConfigureAwait(false)
            // will use the default synchronization context
            Diag.PrintContext("ENTER");
            await WorkWithoutCA();

            Diag.PrintContext("EXIT");
        }
示例#5
0
        public async Task Run()
        {
            // async calls run on a completely different thread (which does
            // not capture the original SynchronizationContext)
            Diag.PrintContext("ENTER");
            await Task.Run(() => WorkWithoutCA());

            Diag.PrintContext("EXIT");
        }
示例#6
0
        public async Task Run()
        {
            // async calls with all awaits marked with ConfigureAwait(false)
            // will try to not use the default synchronization context
            Diag.PrintContext("ENTER");
            await WorkWithFullCA();

            Diag.PrintContext("EXIT");
        }
示例#7
0
        public async Task Run()
        {
            // async calls with just the initial method's awaits marked
            // with ConfigureAwait(false)
            // will try to not use the default synchronization context
            Diag.PrintContext("ENTER");
            await WorkWithShallowCA();

            Diag.PrintContext("EXIT");
        }
示例#8
0
        private async Task WorkWithoutCA()
        {
            Diag.PrintContext("ENTER");

            await DoWorkAsync(cycleCount).PrintContext();
            await DoWorkAsync(cycleCount).PrintContext();
            await DoWorkAsync(cycleCount).PrintContext();

            Diag.PrintContext("EXIT");
        }
示例#9
0
        private async Task WorkWithFullCA()
        {
            Diag.PrintContext("ENTER");

            await DoWorkAsyncCA(cycleCount).PrintContext().ConfigureAwait(false);
            await DoWorkAsyncCA(cycleCount).PrintContext().ConfigureAwait(false);
            await DoWorkAsyncCA(cycleCount).PrintContext().ConfigureAwait(false);

            Diag.PrintContext("EXIT");
        }
示例#10
0
        private async Task WorkWithoutCA()
        {
            Diag.PrintContext("ENTER");
            await new SynchronizationContextRemover();     // this await strips the
                                                           // SynchronizationContext for
            await DoWorkAsync(cycleCount).PrintContext();  // the rest of the this method
            await DoWorkAsync(cycleCount).PrintContext();
            await DoWorkAsync(cycleCount).PrintContext();

            Diag.PrintContext("EXIT");
        }
示例#11
0
        private async Task WorkWithShallowCA()
        {
            // only has ConfigureAwait at this level, children do not.
            Diag.PrintContext("ENTER");

            await DoWorkAsync(cycleCount).PrintContext().ConfigureAwait(false);
            await DoWorkAsync(cycleCount).PrintContext().ConfigureAwait(false);
            await DoWorkAsync(cycleCount).PrintContext().ConfigureAwait(false);

            Diag.PrintContext("EXIT");
        }
示例#12
0
        private async Task BlockingWorkAsync(uint cycles)
        {
            // Perform both async blocking and synchronous blocking
            Diag.PrintContext("ENTER");
            await Task.Delay(1000).PrintContext();

            Thread.Sleep(1000);

            await Task.Delay(1000).PrintContext();

            Diag.PrintContext("EXIT");
        }