?
Solved

Wait Function in VB .NET??

Posted on 2006-10-28
5
Medium Priority
?
1,701 Views
Last Modified: 2008-02-01
Anyone know of a wait function I can use in vb .NET to pause the program while I wait for my (form based) web browser to load (i.e. to reach readystate_complete)?

I tried this:
 - create a form class (with a webbrowser on it)
 - create a bool variable in this class called load_complete (this boolean gets set to true for each instance of the class when that instance's WebBrowser document_complete event gets fired)
 - create a class called DoStuff which inherits the form class
 - within a sub in the DoStuff class, create a form object and navigate its axWebBrowser1 to some url
 - send this sub into a loop waiting for the complete_load property of the form object to be set to true.........Do While form.complete_load <> true Sleep(100) Loop
 - the idea was that when document_complete gets fired for the instance of the form, that instance's load_complete property would get set to true and the DoStuff sub's loop would be exited leaving that sub to move on with its life

There is a problem with this approach in that sleep(100) seems to kill all processing in the program which means the document_complete event of the form classes browser doesnt get fired (I dont even think the webbrowser makes it to the page, it just hangs).

I need something that pauses the program but will not stop document_complete getting fired when the webbrowser has succesfully loaded the page.

Thanks
0
Comment
Question by:RaindogRob
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 35

Expert Comment

by:Raynard7
ID: 17827001
Hi,

this seems like a solution where threading would be optimal.

I would create one thread for the loading of this document and another to check its progress.
I would have the main thread (checking for the progress of the other) to call its thread.sleep method but this should allow all other threads to still operate.

You could also use a mutex - ie create worker thread to load the web browser - then get it to enter a protected mutex - then have your main thread enter the mutex,
then only when the other thread has finished does it release the mutex and your main thread can continue.

If you are totally lost with threading http://www.devx.com/DevX/10MinuteSolution/20365/1954?pf=true has a pretty good descripton about how to do this.
0
 
LVL 10

Expert Comment

by:gangwisch
ID: 17827113
use system.thread.sleep(1000) ' will hold for 1 second
0
 
LVL 14

Expert Comment

by:ptakja
ID: 17830877
Raynard7 has the solution. Threading is the way to go.

Gangwisch, your solution will cause the CURRENT thread to sleep, thus ALL processing on that thread will be suspended for the duration specified leaving the author in the same boat.
0
 

Author Comment

by:RaindogRob
ID: 17846212
Thanks Raynard7, sounds like threading will do the trick (the article you recommended was pretty clear too). One problem though, I've put together a program that works like this:

Sub DoStuff()
        Dim somearray(10) As classname
        Dim ThreadArray(10) As System.Threading.Thread

        For Count = 1 To 10
            array(Count) = New classname
            ThreadArray(count) = New System.Threading.Thread(AddressOf otherclass(count).DelegateFunctionName)
        Next Count

        For Count = 1 To 10
            ThreadArray(Count).Start()
        Next Count
End Sub

The problem is this:
 - After the threads in ThreadArray have all been started, I need the DoStuff Sub to pause/sleep (leaving all the threads in the ThreadArray to run to completion) - I cant have DoStuff continuing until a bool property of the second class is set to true (this happens in the delegate function)
 - I have tried putting System.Threading.Thread.CurrentThread.Sleep(1000) at the end of the above code but that seems to freeze the entire program (i.e. even the ThreadArray threads seems to stop running with this).
 - To test this, I have put a msgbox in to alert me when each individual thread has finished executing (at the end of the delegate function). When I start each of the threads (as in the code above) and then use System.Threading.Thread.CurrentThread.Sleep(10000) as the final line of code in the dostuff sub, I would expect to see each delegate function msgbox pop up before the DoStuff sub is exited (i.e. before the Currentthread.Sleep(10000) has completed). This is not the case - instead the delegate function msgboxes are not coming up until the DoStuff System.Threading.Thread.CurrentThread.Sleep(10000) line has completed.

This is causing me a huge headache as it makes it look like the ThreadArray threads are not running concurrent with the DoStuff sub.

I'd really appreciate any help you can give me.

Thanks

I can resubmit this as another question for 500 pts if you like.
0
 
LVL 35

Accepted Solution

by:
Raynard7 earned 2000 total points
ID: 17848198
Hi Rob, sorry have been busy all day - I'd suggest that you create another post to ask your new question
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month11 days, 22 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question