Results 1 to 3 of 3

Thread: [RESOLVED] Wait for WebBrowser WebBrowserReadyState.Complete when no async CallBack can be used

  1. #1

    Thread Starter
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Resolved [RESOLVED] Wait for WebBrowser WebBrowserReadyState.Complete when no async CallBack can be used

    The App i'm working with has no Form, it's just a single instance Run Application, it runs and closes, so i can't catch asyncronic events thrown by Webbrowser, i've used Document_Complete() event in the past but is there any alternative when there is no Form?

    I know a loop like this would work, not allowing execution to continue until the state changes, but i just wanted to know if there exist something better since it's known as a bad practice in .Net:
    Code:
            Do While (wb.ReadyState <> WebBrowserReadyState.Complete)
                Application.DoEvents()
            Loop

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Wait for WebBrowser WebBrowserReadyState.Complete when no async CallBack can be u

    It sounds like you have no choice but to use a loop but don't put Application.DoEvents inside it. There are no events to do so that doesn't do anything for you. All it does is max out the CPU usage. Put a Thread.Sleep call in there so that at least the app is doing nothing each iteration. A period of 100 will mean that you wait no longer than 1/10 of a second between when the document actually finishes loading and when you move on from the loop, which should be good enough for anyone. You could probably go to 500 or even 1000 and still not have an issue.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Wait for WebBrowser WebBrowserReadyState.Complete when no async CallBack can be u

    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width