Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This is the method which starts the whole checking process
- BackgroundWorker[] bgw = new BackgroundWorker[Properties.Settings.Default.Threads];
- string[] args = new string[2];
- int temp = -1;
- for (int i = 0; i < Properties.Settings.Default.Threads; i++)
- {
- bgw[i] = new BackgroundWorker();
- bgw[i].DoWork += new DoWorkEventHandler(this.bgWorker_DoWorkPing);
- bgw[i].RunWorkerCompleted += new RunWorkerCompletedEventHandler(this.bgWorker_RunWorkerCompleted);
- temp = GetNextinQueue();
- if (temp != -1)
- {
- args[0] = temp.ToString();
- args[1] = lvProxy.Items[temp].SubItems[0].Text;
- bgw[i].RunWorkerAsync(args);
- }
- else
- break;
- }
- private void bgWorker_DoWorkPing(object sender,DoWorkEventArgs e)
- {
- BackgroundWorker worker = sender as BackgroundWorker;
- string[] args = e.Argument as string[];
- e.Result = new long[] {long.Parse(args[0]),ExecutePing(args[1])};
- }
- private void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
- {
- if (e.Error != null)
- {
- MessageBox.Show(e.Error.Message);
- }
- else if (e.Cancelled)
- {
- s("Checking was aborted...");
- }
- else
- {
- long[] res = e.Result as long[];
- lvProxy.Items[(int)res[0]].SubItems[2].Text = res[1].ToString();
- this.lvProxy.Sort();
- int next = GetNextinQueue();
- if (next != -1)
- {
- BackgroundWorker bgw = sender as BackgroundWorker;
- bgw.RunWorkerAsync(new string[] {next.ToString(),lvProxy.Items[next].SubItems[0].Text});
- }
- }
- }
- private long ExecutePing(string ip)
- {
- Ping p = new Ping();
- PingReply pr = p.Send(ip, Properties.Settings.Default.Timeout,Form1.testdata);
- switch (pr.Status)
- {
- case IPStatus.Success:
- {
- return pr.RoundtripTime;
- }
- case IPStatus.TimedOut:
- {
- return -1;
- }
- default:
- {
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment