static void run_awaits(string[] hosts) { List <Task> tasks = new List <Task>(); var i = 0; foreach (var host in hosts) { PageReader.Execute(host, 80, (Socket s) => { tasks.Add(new Await(s, (string res) => { System.IO.File.WriteAllText(host + i++ + ".txt", res); Console.WriteLine(res); }).readPage()); }); } Task.WaitAll(tasks.ToArray()); }
static void run_callbacks(string[] hosts) { CountdownEvent cde = new CountdownEvent(hosts.Length); var i = 0; foreach (var host in hosts) { PageReader.Execute(host, 80, (Socket s) => { new Tasks(s, (string res) => { System.IO.File.WriteAllText(host + i++ + ".txt", res); Console.WriteLine(res); cde.Signal(); }).readPage(); }); } cde.Wait(); }