Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void startFilterBtn_Click(object sender, EventArgs e)
- {
- skipProxyCheckBtn.Enabled = false;
- cts = new CancellationTokenSource();
- CancellationToken ct = cts.Token;
- List<string> proxyCheckList = new List<string>();
- foreach (var prox in rawProxyList.Items)
- {
- proxyCheckList.Add(prox.ToString());
- }
- int x = 0;
- int y = Convert.ToInt32(totalProxiesLabel.Text);
- // this.ProxyCheckList = proxyCheckList;
- proxyBar.Maximum = proxyCheckList.Count; //this.ProxyCheckList.Count;
- var TaskMain = Task.Factory.StartNew(() =>
- {
- try
- {
- ct.ThrowIfCancellationRequested();
- Parallel.ForEach(proxyCheckList,
- new ParallelOptions { MaxDegreeOfParallelism = Convert.ToInt32(filterThreadCount.Text), CancellationToken = ct }, proxy =>
- {
- // check the proxies
- CheckProxys(proxy, ct);
- Interlocked.Increment(ref x);
- Interlocked.Decrement(ref y);
- // Delegate for accessing controls
- Invoke(new MethodInvoker(
- delegate()
- {
- totalProxiesLabel.Text = y.ToString();
- rawProxyList.Items.RemoveAt(o);
- proxyBar.Value = x;
- }));
- });
- }
- // catch cancel exceptions
- catch (OperationCanceledException)
- {
- Invoke(new MethodInvoker(
- () =>
- {
- skipProxyCheckBtn.Enabled = true;
- proxyBar.Value = 0;
- }));
- return;
- }
- catch (ObjectDisposedException)
- {
- Invoke(new MethodInvoker(
- () =>
- {
- skipProxyCheckBtn.Enabled = true;
- proxyBar.Value = 0;
- }));
- }
- catch (Exception)
- {
- Invoke(new MethodInvoker(
- () =>
- {
- skipProxyCheckBtn.Enabled = true;
- proxyBar.Value = 0;
- }));
- }
- }, ct);
- }
Advertisement
Add Comment
Please, Sign In to add comment