Guest User

Untitled

a guest
Oct 3rd, 2013
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // This is what called when button is clicked
  2.  
  3. Task t3 = new Task(SpawnTask);
  4.             t3.Start();
  5.             t3.Wait();
  6.  
  7. //if noofthreads are less 50 then GUI is woking fine.. if number increases then GUI takes much time for repaint.. where as other
  8. //softwares are working without any problem even if the threads are more than 500!! in the same system
  9.  public void SpawnTask()
  10.         {
  11.             try
  12.             {
  13.                 ParallelOptions po = new ParallelOptions();
  14.                 po.CancellationToken = cts.Token;
  15.                 po.MaxDegreeOfParallelism = noofthreads;
  16.                 Parallel.ForEach(
  17.                 urls,
  18.                 po,
  19.                 url => checkpl(url));
  20.             }
  21.             catch (Exception ex)
  22.             {
  23.  
  24.             }
  25.         }
  26.  
  27.  
  28. public void checkpl(string url)
  29.         {
  30.  
  31.             try
  32.     {
  33.     HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  34.             request.Timeout = 60*1000;
  35.             HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  36.             string stext = "";
  37.             using (BufferedStream buffer = new BufferedStream(response.GetResponseStream()))
  38.             {
  39.                 using (StreamReader reader = new StreamReader(buffer))
  40.                 {
  41.                     stext = reader.ReadToEnd();
  42.                 }
  43.             }
  44.             response.Close();
  45.         if (stext .IndexOf("domainname.com") != -1)
  46.             {
  47.                 tfound = tfound  + 1;
  48.                 string lext = "Total Found : "+tfound.ToString();
  49.                 label3.BeginInvoke(new InvokeDelegate(UpdateLabel), ltext);
  50.                 slist.Add(url);
  51.  
  52.                 textBox2.BeginInvoke(new InvokeDelegate4(UpdateText), "Working Url " + url);
  53.                
  54.             }
  55.     }
  56.  catch (Exception ex)
  57.             {
  58.        
  59.             }
  60.         }
Advertisement
Add Comment
Please, Sign In to add comment