Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have developed a simple Id checking windows forms with C# application to check a set of given Ids valid or not by passing to a webpage using webbrowser control and getting the reply and everything is working fine,its taking 40 - 60 seconds for 20 Ids.one by one.Now i want to speed up the same process using advance threading concept in C# .

my working code as under .

private void button2_Click(object sender, EventArgs e)
       {
           string url = "https://idscheckingsite.com";
           WebBrowser wb = new WebBrowser();
           wb.ScriptErrorsSuppressed = true;
           wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(Final_DocumentCompleted);
           wb.Navigate(url);

       }



private void Final_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
       {
           WebBrowser wbs = sender as WebBrowser;
           wbs.Document.GetElementById("pannumber").InnerText = ListsofIds[ids];
           wbs.Document.GetElementById("frmType1").SetAttribute("value", "24Q");
           HtmlElement btnlink = wbs.Document.GetElementById("clickGo1");
           btnlink.InvokeMember("Click");

           //string response = wbs.DocumentText;
           wbs.DocumentCompleted -= new WebBrowserDocumentCompletedEventHandler(Final_DocumentCompleted);
           wbs.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(Final_result);
       }


private void Final_result(object sender, WebBrowserDocumentCompletedEventArgs e)
       {

           WebBrowser wbResult = sender as WebBrowser;

           string status = wbResult.Document.GetElementById("status").InnerText;
           string name = wbResult.Document.GetElementById("name").InnerText;

           wbResult.DocumentCompleted -= new WebBrowserDocumentCompletedEventHandler(Final_result);
           wbResult.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(Final_DocumentCompleted);

           DataRow dr = dt.NewRow();

           dr[0] = PANNumber[ids];
           dr[1] = status;
           dr[2] = name;

           dt.Rows.Add(dr);
           ++ids;

           if (ids < 20)
               wbResult.Navigate(vurl);
           else
           {
               dataGridView1.DataSource = dt;
           }
       }


How to improve the performance to the Maximum using threading in C# . Please help me its urgent . thanks in Advance .

- Martin

What I have tried:

tried using windows webbrowser control taking 44 - 60 seconds for 20 ids checking .
Posted
Updated 18-Jul-19 23:40pm
Comments
Richard MacCutchan 18-Jul-19 6:48am    
There is no guarantee that threading will make any difference. You first need to find out where the bottleneck is. If most of the delay is with network traffic then there is little that you can do to improve the processing speed.

And by the way, this is not in any way urgent to people here.

1 solution

If it were me, I'd send HTTP requests and evaluate the un-rendered response instead of waiting for a web page to render. You could try putting each request in a thread.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900