Hack Forums
[.NET] How to sleep without the program freezing? Or how to wait for webbrowser to load page - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] How to sleep without the program freezing? Or how to wait for webbrowser to load page (/showthread.php?tid=1700071)



How to sleep without the program freezing? Or how to wait for webbrowser to load page - SIM-524734 - Sep 7, 2011

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.


* - Coleak - Sep 7, 2011

(Sep 7, 2011 07:40 AM)Ecoste 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.


* - Chuck Norris . - Sep 7, 2011

for webbrowser is webbrowser_documentcompleted or something like this
system.threading.thread.sleep(time)
or using system time.


* - SIM-524734 - Sep 7, 2011

(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.


* - Coleak - Sep 7, 2011

(Sep 7, 2011 07:45 AM)Ecoste 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?


* - SIM-524734 - Sep 7, 2011

(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.


* - Chuck Norris . - Sep 7, 2011

(Sep 7, 2011 07:45 AM)Ecoste 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




* - FileX - Sep 7, 2011

Code
WebBrowser1.Navigate("http://www.lol.com")
  While WebBrowser1.ReadyState <> WebBrowserReadyState.Complete 'When WebBrowser complete page's loading..
    Application.DoEvents()
  End While



* - SIM-524734 - Sep 7, 2011

(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.


* - FileX - Sep 7, 2011

(Sep 7, 2011 08:03 AM)Ecoste 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.


* - Coleak - Sep 7, 2011

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)