Exemplo n.º 1
0
 public Task StartTask(string combination)
 {
     Task = Task.Factory.StartNew(new Action <object>((workedProxy) =>
     {
         string workedProxyString = string.Empty;
         if (workedProxy != null)
         {
             workedProxyString = workedProxy.ToString();
         }
         string correctProxy     = string.Empty;
         bool connectionAccepted = false;
         do
         {
             if (string.IsNullOrEmpty(workedProxyString))
             {
                 correctProxy  = WebHelper.GetRandomProxyAddress();
                 proxiedClient = WebHelper.CreateProxiedClient(correctProxy);
             }
             else
             {
                 correctProxy = workedProxyString;
             }
             if (string.IsNullOrEmpty(correctProxy))
             {
                 Debug.WriteLine("Return because proxy is null");
                 return;
             }
             try
             {
                 proxiedClient.DownloadData(WebHelper.amazonPageUrl);
                 connectionAccepted = true;
                 workedProxyAddress = correctProxy;
             }
             catch (Exception ex)
             {
                 WebHelper.Proxies.TryRemove(correctProxy, out int value);
                 workedProxyAddress = string.Empty;
                 workedProxyString  = string.Empty;
                 Debug.WriteLine(WebHelper.Proxies.Count);
             }
         } while (!connectionAccepted);
         SearchItemOnPage(combination);
     }), workedProxyAddress);
     return(Task);
 }