coolerfarmer

Untitled

Jun 12th, 2014
5,519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. private void startFilterBtn_Click(object sender, EventArgs e)
  2. {
  3. skipProxyCheckBtn.Enabled = false;
  4. cts = new CancellationTokenSource();
  5. CancellationToken ct = cts.Token;
  6.  
  7. List<string> proxyCheckList = new List<string>();
  8.  
  9. foreach (var prox in rawProxyList.Items)
  10. {
  11. proxyCheckList.Add(prox.ToString());
  12. }
  13.  
  14. int x = 0;
  15. int y = Convert.ToInt32(totalProxiesLabel.Text);
  16.  
  17. // this.ProxyCheckList = proxyCheckList;
  18.  
  19. proxyBar.Maximum = proxyCheckList.Count; //this.ProxyCheckList.Count;
  20.  
  21. var TaskMain = Task.Factory.StartNew(() =>
  22. {
  23. try
  24. {
  25. ct.ThrowIfCancellationRequested();
  26.  
  27. Parallel.ForEach(proxyCheckList,
  28. new ParallelOptions { MaxDegreeOfParallelism = Convert.ToInt32(filterThreadCount.Text), CancellationToken = ct }, proxy =>
  29. {
  30. // check the proxies
  31. CheckProxys(proxy, ct);
  32.  
  33. Interlocked.Increment(ref x);
  34. Interlocked.Decrement(ref y);
  35.  
  36. // Delegate for accessing controls
  37. Invoke(new MethodInvoker(
  38. delegate()
  39. {
  40. totalProxiesLabel.Text = y.ToString();
  41.  
  42. rawProxyList.Items.RemoveAt(o);
  43.  
  44. proxyBar.Value = x;
  45. }));
  46. });
  47. }
  48. // catch cancel exceptions
  49. catch (OperationCanceledException)
  50. {
  51. Invoke(new MethodInvoker(
  52. () =>
  53. {
  54. skipProxyCheckBtn.Enabled = true;
  55. proxyBar.Value = 0;
  56. }));
  57. return;
  58. }
  59. catch (ObjectDisposedException)
  60. {
  61. Invoke(new MethodInvoker(
  62. () =>
  63. {
  64. skipProxyCheckBtn.Enabled = true;
  65. proxyBar.Value = 0;
  66. }));
  67. }
  68. catch (Exception)
  69. {
  70. Invoke(new MethodInvoker(
  71. () =>
  72. {
  73. skipProxyCheckBtn.Enabled = true;
  74. proxyBar.Value = 0;
  75. }));
  76. }
  77. }, ct);
  78. }
Advertisement
Add Comment
Please, Sign In to add comment