[RESOLVED] [2005] Wait+webbrowser
I have a button that does multiple things, but I want it to wait a certain amount of time in between doing different actions. how would I do so?
the first function is to navigate the webbrowser to a certain page, and the second function can only be done once the webpage is loaded, but the webpage only loads at the end...
Thnx
Phil.
Re: [2005] Wait+webbrowser
take the call to the second function out of the button click event, and move it to the document complete event. The document complete event fires when the webpage has fully loaded.
A side note to this is if you visit a page with frames, the DocumentComplete event fires for every frame that is loaded, and then a final time when everything is done. If the page does NOT have frames, DocumentComplete fires simply once when the page is loaded.
Re: [2005] Wait+webbrowser
oh sweet, how do i write the documentcomplete event?
but the thing is that each event are in a For...Loop with a variable that is only used in the loop, so I can't move the code into an other function
Re: [2005] Wait+webbrowser
Quote:
Originally Posted by smart_phil_dude1
oh sweet, how do i write the documentcomplete event?
The same way you write code for a button click event. The documentcomplete event is just an event the control fires. Just go to the code view of the form, select the webbrowser control from the left combobox at the top of the code window, and select the documentcomplete event from the right dropdown and it will insert the needed prototype and you can code away.
Quote:
Originally Posted by smart_phil_dude1
but the thing is that each event are in a For...Loop with a variable that is only used in the loop, so I can't move the code into an other function
Then you need to go back and figure out another way to code it ;)
Re: [2005] Wait+webbrowser
Quote:
Then you need to go back and figure out another way to code it
then is there a way to just make it wait a certain amount of time?
Re: [2005] Wait+webbrowser
you could try doing
system.threading.thread.sleep(x)
where x is the number of milliseconds to make it sleep.
However this sleeps the entire thread, and it may cause undesirable results.
You can try it though.
Re: [2005] Wait+webbrowser
nope, the browser doesn't load.
Re: [2005] Wait+webbrowser
that is what I figured.
I don't know what you are trying to do in this loop of yours, so it is hard to make suggestions ;)
Re: [2005] Wait+webbrowser
well, what it does is load page number 1 that is in the first line of a textbox, then manipulate things on the webpage, then load page number 2 that is on the second line of the textbox, etc. until it has done each page on each line. and it also visits more than one webpage per line of the textbox, if you get what i mean...
is there a function that can make it just wait until the page has loaded, and then continue?
Re: [2005] Wait+webbrowser
if I were coding it... I would do this:
when the button is clicked, it navigates the webbrowser to the first line of the textbox.
when the documentcomplete event of the webbrowser fires, I would do whatever manipulation needs to be done. I would also check the URL of the webbrowser at this point to see if it has visited the last page it needs to for the given line in the textbox. When that happens, I would make a call to read the next line of the textbox and do it all over again until all lines were processed.
No loop needed, just a counter to keep track of what line in the textbox should get processed next.
Re: [2005] Wait+webbrowser
ok i get what you mean, but i made it visit more than one page per line, and on each page it does different things... would it be possible of having more than one documentcomplete event, one for each page?
Re: [2005] Wait+webbrowser
the documentcomplete event fires whenever a given webpage has finished loading.
Checking the browsers current URL in the documentcomplete event (you can do this using the event args of the documentcomplete event (e.Url.ToString))
so by checking the current URL in the document complete event, you can do whatever manipulation needs to be done for the given page.
Re: [2005] Wait+webbrowser
oh sweet thanks a lot now i know exactly what to do :D