Mead Alsorani

Mead Alsorani

  • 1.6k
  • 10
  • 510

Hanging HtmlAgilityPack Task

Jan 1 2020 10:03 AM
I am trying to parse an html page with HtmlAgilityPack to Extract links from it then add links to ListBox then add the links from listBox to queue.
I have three Tasks(PageParse,AddItemsToList,EnqueueFromList)
OK My problem is when I click the button the whole Application is hanging.
button Code  
  1. private void CrawdBtn_Click(object sender, EventArgs e)  
  2.     {  
  3.         t = Task.Factory.StartNew(PageParse);  
  4.         t.Wait();  
  5.         TaskAddToList = Task.Factory.StartNew(() => AddItemsToList(t.Result));  
  6.         TaskAddToList.Wait();  
  7.   
  8.         b = new Task(EnqueueFromList);  
  9.         b.Start();  
  10.         //Task.WaitAll(t,b);  
  11.         CrawdBtn.Enabled = true;  
  12.   
  13.     }  
Page Parse Method
  1. public HtmlAgilityPack.HtmlDocument PageParse()  
  2.     {  
  3.         MessageBox.Show($"Page Parse Has started");  
  4.   
  5.         web = new HtmlWeb();  
  6.         doc = new HtmlAgilityPack.HtmlDocument();  
  7.         doc = web.Load(UrlText.Text);  
  8.   
  9.   
  10.   
  11.         return doc;  
  12.     }  
I have Noticed by following breakpoints That the debugger is hanging when it goes to execute PageParse Method