using System;
using System.Threading.Tasks;
using System.Threading;
using System.Collections.Generic;
using System.Diagnostics;
class MainClass {
static int SleepTime = 1000;
static int ForCount = 100;
static List<Task> Tasks = new List<Task>();
public static void Main (string[] args)
{
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
Console.WriteLine("async Started");
Task t = null;
for (int i =0; i < ForCount; ++i)
{
t = StartAsyncTasks();
Tasks.Add(t);
}
Task.WaitAll(Tasks.ToArray());
Console.WriteLine("async Finished");
Console.WriteLine("in " + stopWatch.Elapsed.Seconds);
Tasks.Clear();
stopWatch.Restart();
StartThreads();
Console.WriteLine("in " + stopWatch.Elapsed.Seconds);
}
public static async Task StartAsyncTasks()
{
await Task.Delay(SleepTime);
}
public static void StartThreads()
{
Console.WriteLine("thread Started");
Task t = null;
for (int i =0; i < ForCount; ++i)
{
t = Task.Run( () => Thread.Sleep(SleepTime));
Tasks.Add(t);
}
Task.WaitAll(Tasks.ToArray());
Console.WriteLine("thread Finished");
}
}