Ejemplo n.º 1
0
        // Just plain o'l sync
        private void SyncBtn_Click(object sender, RoutedEventArgs e)
        {
            ClearOutput();
            DisplayTaskDetails("Sync Task Running...\n");

            var watch = System.Diagnostics.Stopwatch.StartNew();

            var output = RunSyncDemo.Start();

            RenderListOutput(output);

            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;

            DisplayTaskDetails("Sync Task Stopped...\n");
            DisplayTaskDetails($"Elapsed Time: {elapsedMs}\n");
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Fetching data - SYNC!");

            var watch  = System.Diagnostics.Stopwatch.StartNew();
            var output = RunSyncDemo.Start();

            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;

            Console.WriteLine($"Total execution time: { elapsedMs }");

            Console.WriteLine("========================");

            Console.WriteLine("Fetching data - ASYNC!");

            // Main returns to the OS - so your program exits.
            Task.Run(async() =>
            {
                var watch = System.Diagnostics.Stopwatch.StartNew();

                var output = await RunAsyncDemo.Start();

                watch.Stop();
                var elapsedMs = watch.ElapsedMilliseconds;
                Console.WriteLine($"Total execution time: { elapsedMs }");
            });

            // As a workaround to the above, we can provide our own async-compatible context
            try
            {
                AsyncContext.Run(() => RunAsyncDemo.Start());
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex);
            }
        }