public void scan(ScunnerOutputContent output) { Task t = Task.Factory.StartNew(() => { List <Task> tasks = new List <Task>(); foreach (MIp ip in addresses) { Task task = Task.Factory.StartNew(() => { new Pinger().ping(ip); output.add(ip); }); tasks.Add(task); } try { Task.WaitAll(tasks.ToArray()); output.update(addresses); /*foreach (MIp ip in addresses) * { * Debug.WriteLine("Out "+ip+" "+ip._status); * * // dataGridView.Invoke(new Set((s) => dataGridView.Rows.Add(s,s.hostname,s._status)),ip); * }*/ } catch (Exception e) { Debug.WriteLine("Exception" + e); Console.WriteLine(e); throw; } }); }
public void scan(ScunnerOutputContent output) { Task t = Task.Factory.StartNew(() => { List <Task> tasks = new List <Task>(); MTaskShelder lcts = new MTaskShelder(100); TaskFactory factory = new TaskFactory(lcts); foreach (MIp ip in addresses) { Task t1 = factory.StartNew(() => { new Pinger().ping(ip); output.add(ip); }); tasks.Add(t1); } /*int max = 255; * int col = 0; * foreach (MIp ip in addresses) * { * Task task = Task.Factory.StartNew(() => * { * new Pinger().ping(ip); * output.add(ip); * }); * tasks.Add(task); * col++; * if (col == max) * { * Task.WaitAll(tasks.ToArray()); * col = 0; * } * }*/ try { Task.WaitAll(tasks.ToArray()); output.update(addresses); } catch (Exception e) { Debug.WriteLine("Exception" + e); Console.WriteLine(e); throw; } }); }