Beispiel #1
0
        public static void ExecuteAsyncTasks()
        {
            var timer = new Stopwatch();

            timer.Start();

            var tasks = new List <Task>();

            for (int i = 0; i < 500; i++)
            {
                tasks.Add(TaskTests.AsyncTestShort());
            }
            Task.WaitAll(tasks.ToArray());

            timer.Stop();
            Console.WriteLine($"Download requests took {timer.Elapsed}");
        }
Beispiel #2
0
        public static void ExecuteSyncTasks()
        {
            var timer = new Stopwatch();

            timer.Start();

            var tasks = new List <Task>();

            for (int i = 0; i < 500; i++)
            {
                tasks.Add(Task.Factory.StartNew(() => { return(TaskTests.Download("http://www.wp.pl")); }));
            }
            Task.WaitAll(tasks.ToArray());

            timer.Stop();
            Console.WriteLine($"Download requests took {timer.Elapsed}");
        }