Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

How to sleep without the program freezing? Or how to wait for webbrowser to load page

Title explains it all, 1 of these answers will solve my problem.

Problem: Get's the source before the page loads, solved by putting a msgbox infront so it will "sleep" the code without freezing it.
(Sep 7, 2011 07:40 AM)SIM-524734 Wrote:  Title explains it all, 1 of these answers will solve my problem.

Problem: Get's the source before the page loads, solved by putting a msgbox infront so it will "sleep" the code without freezing it.

I don't really understand you question, but if you are wanting thebsource of a website, use a webclient to download it.
for webbrowser is webbrowser_documentcompleted or something like this
system.threading.thread.sleep(time)
or using system time.
(Sep 7, 2011 07:43 AM)Chuck Norris . Wrote:  for webbrowser is webbrowser_documentcompleted or something like this
system.threading.thread.sleep(time)
or using system time.

system.threading.thread.sleep(time)

^^ Freezes the program for that time.

webbrowser_documentcompleted

^^ Have no idea what you talking about, well, you can sub it but then I need multiple pages.

or using system time.

^^ How you do that :S
(Sep 7, 2011 07:43 AM)Coleak Wrote:  I don't really understand you question, but if you are wanting thebsource of a website, use a webclient to download it.

Heres the problem, I have semi-slow internet, so when I navigate the webbrowser to a webpage it takes about 3 seconds to load, but it gets the source code before it loads. Therefore the source code (html) of the page doesn't appear, but when I add a messagebox for the program to wait and load the page, and then press ok to execute the rest of the code, it works.
(Sep 7, 2011 07:45 AM)SIM-524734 Wrote:  system.threading.thread.sleep(time)

^^ Freezes the program for that time.

webbrowser_documentcompleted

^^ Have no idea what you talking about, well, you can sub it but then I need multiple pages.

or using system time.

^^ How you do that :S

Heres the problem, I have semi-slow internet, so when I navigate the webbrowser to a webpage it takes about 3 seconds to load, but it gets the source code before it loads. Therefore the source code (html) of the page doesn't appear, but when I add a messagebox for the program to wait and load the page, and then press ok to execute the rest of the code, it works.

So your objective here is to download a sites source?
(Sep 7, 2011 07:50 AM)Coleak Wrote:  So your objective here is to download a sites source?

mmyes, but I can't do that if the page didn't load first.
(Sep 7, 2011 07:45 AM)SIM-524734 Wrote:  system.threading.thread.sleep(time)

^^ Freezes the program for that time.

webbrowser_documentcompleted

^^ Have no idea what you talking about, well, you can sub it but then I need multiple pages.

or using system time.

^^ How you do that :S

Heres the problem, I have semi-slow internet, so when I navigate the webbrowser to a webpage it takes about 3 seconds to load, but it gets the source code before it loads. Therefore the source code (html) of the page doesn't appear, but when I add a messagebox for the program to wait and load the page, and then press ok to execute the rest of the code, it works.

Code
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

End Sub

and use a timer...

Code
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

  'do what u want here
  Timer1.Stop()
    End Sub

Code
WebBrowser1.Navigate("http://www.lol.com")
  While WebBrowser1.ReadyState <> WebBrowserReadyState.Complete 'When WebBrowser complete page's loading..
    Application.DoEvents()
  End While
[Image: DIZMPqM.png]
(Sep 7, 2011 07:55 AM)Chuck Norris . Wrote:  
Code
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

End Sub

and use a timer...

Code
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

  'do what u want here
  Timer1.Stop()
    End Sub

Yes, I had the timer plan as a backup, but I don't want to make the shit confusing and messy so I was wondering if theres an alternative.
(Sep 7, 2011 08:02 AM)FileX Wrote:  
Code
WebBrowser1.Navigate("http://www.lol.com")
  While WebBrowser1.ReadyState <> WebBrowserReadyState.Complete 'When WebBrowser complete page's loading..
    Application.DoEvents()
  End While

Thank you very much! This method had worked! Props to you sir.
(Sep 7, 2011 08:03 AM)SIM-524734 Wrote:  Yes, I had the timer plan as a backup, but I don't want to make the shit confusing and messy so I was wondering if theres an alternative.

Thank you very much! This method had worked! Props to you sir.

No pleasure dude :) Feel free to ask if you need any help.
[Image: DIZMPqM.png]
Or try this simple code:

Imports system.net

Dim wc as new webclient
Dim website as string = "www.website.com"
Dim websitesource as string = wc.downloadstring(website)
messagebox(websitesource)


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by bytespmApr 5, 2025 08:33 AM 10 454 Apr 5, 2025 08:33 AM
Last Post: Robert Rouge
[.NET] by D3ath_GuNMay 28, 2020 05:04 AM 17 334 May 28, 2020 05:04 AM
Last Post: VisualSoft
[.NET] by ThatAlbinoFrogJul 31, 2018 05:06 PM 6 306 Jul 31, 2018 05:06 PM
Last Post: ThatAlbinoFrog