private void Bw_StartTestCompleted(object sender, RunWorkerCompletedEventArgs e) { string[] param1 = e.Result as string[]; ProxyTestList lst = new ProxyTestList(Convert.ToInt32(param1[0]), param1[1].ToString(), param1[2].ToString(), param1[3].ToString()); laoder_space.Children.Clear(); //list_view.Children.Clear(); list_view.Children.Add(lst); }
public void populateList(string[] pr, string url) { var count = 0; list_view.Children.Clear(); foreach (var p in pr) { if (p != null && p != "") { count++; try { //WebClient client = new WebClient(); //WebProxy proxy1 = new WebProxy(p.Split(':')[0] + ":" + p.Split(':')[1], true); //proxy1.Credentials = new NetworkCredential(p.Split(':')[2], p.Split(':')[3]); ////proxy1.UseDefaultCredentials = true; //WebRequest.DefaultWebProxy = proxy1; //client.Proxy = proxy1; //if (client.IsBusy) { // System.Threading.Thread.Sleep(2000); //} //else{ // var s = client.Headers; // string str = client.DownloadString(url); //} BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += Bw_StartTest; bw.RunWorkerCompleted += Bw_StartTestCompleted; bw.WorkerSupportsCancellation = true; //Parameter you need to work in Background-Thread for example your strings string[] param = new[] { p, url, count.ToString() }; //Start work bw.RunWorkerAsync(param); } catch (Exception ex) { ProxyTestList lst = new ProxyTestList(count, p, url, ex.Message); list_view.Children.Clear(); list_view.Children.Add(lst); } } } }