-
Memory eater
Hey!
I use the following piece of code(Not mine!) to wait for the web browser to fully load the page.
It works perfect but its not good for the memory because this method is used allot.
Any optimization tips?
Code:
private void waitTillLoad(WebBrowser webbrowser)
{
WebBrowserReadyState loadStatus;
//wait till beginning of loading next page
int waittime = 100000;
int counter = 0;
while (true)
{
loadStatus = webbrowser.ReadyState;
Application.DoEvents();
if ((counter > waittime) || (loadStatus == WebBrowserReadyState.Uninitialized) || (loadStatus == WebBrowserReadyState.Loading) || (loadStatus == WebBrowserReadyState.Interactive))
{
break;
}
counter++;
}
//wait till the page get loaded.
counter = 0;
while (true)
{
loadStatus = webbrowser.ReadyState;
Application.DoEvents();
if (loadStatus == WebBrowserReadyState.Complete)
{
break;
}
counter++;
}
}
-
Re: Memory eater
-
Re: Memory eater
Why do you think this consumes too much memory? Have you profiled your app? I see nothing in there that would be problematic (well, I would probably launch the browser asynchronously instead of waiting in a loop and doing ugly thing like DoEvents()) as far as memory is concerned. It looks to me like you are making an assumption about the performance of your code that is ill informed and most likely false.