|
-
Aug 1st, 2003, 01:21 AM
#1
Thread Starter
Frenzied Member
VB.net - multithreading question
I havent got vb.net yet, thinking of purchasing it.
im just wondering, will
VB Code:
Public Sub thread1()
WB.Navigate "http://www.google.ca"
Do: Doevents: Loop until wb.busy = false
debug.print "Done"
End Sub
Public Sub thread2()
WB2.Navigate "http://www.google.ca"
Do: Doevents: Loop until wb2.busy = false
debug.print "Done"
End Sub
Public Sub AllThread()
'Combine the two subs in one sub so they can be
'fired at once
Me.thread1()
Me.thread2()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim thrd As Threading.Thread
thrd = New Threading.Thread(AddressOf AllThread)
thrd.Start()
End Sub
will that Doevents run only for that specific thread? so that each thread will wait until the browser is done loading? or will once thread1 execute, the doevents will make the whole program wait for it to be done?
-
Aug 1st, 2003, 06:42 AM
#2
Fanatic Member
me neither, but from my experience, as far as I can tell, DoEvents
is just to ask the thread to jump out of the procedure temporarily
and fire other events. So, if it's running in a new thread, even
if you don't put a DoEvents, it won't halt your process.
So I guess putting things like this won't halt stuffs:
VB Code:
Public Sub thread1()
WB.Navigate "http://www.google.ca"
Do: Loop until wb.busy = false
debug.print "Done"
End Sub
Public Sub thread2()
WB2.Navigate "http://www.google.ca"
Do: Loop until wb2.busy = false
debug.print "Done"
End Sub
Public Sub AllThread()
'thread2 would still have to wait for thread1 to finish.
'so this procedure is useless. I make two threads instead.
'Me.thread1()
'Me.thread2()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim thrd1 As Threading.Thread
Dim thrd2 As Threading.Thread
Set thrd1 = New Threading.Thread(AddressOf thread1)
Set thrd2 = New Threading.Thread(AddressOf thread2)
thrd1.Start()
thrd2.Start()
End Sub
Your code should be just like above if you want both procedure
i.e thread1 and thread2 to run at once.
ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
Programming is fun, but only if you're not on a tight deadline 
So I consider all those working engineers sad people
VB FTP class
3 page PHP crash course
Crash Course on DX9 Managed with VB.NET covering basics till terrain creation
-
Aug 1st, 2003, 06:48 AM
#3
I'm pretty sure that the Thread class has a Sleep() method that suspends the current thread and allows others to execute. You would use that over a DoEvents. Application.DoEvents is just there for compatibility I imagine.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Aug 1st, 2003, 03:32 PM
#4
Thread Starter
Frenzied Member
yea, but thread.sleep needs a value assigned with it (as in sleep x amount of time)
im pretty sure a do/loop will take 100% cpu as it loops over and over that same code until something changes to true..
is there any way to not use 100% cpu?
what would be the best way to download 2 pages with 2 webbrowsers and check if its done loading? (without using events)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|