Results 1 to 4 of 4

Thread: VB.net - multithreading question

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269

    VB.net - multithreading question

    I havent got vb.net yet, thinking of purchasing it.

    im just wondering, will
    VB Code:
    1. Public Sub thread1()
    2.         WB.Navigate "http://www.google.ca"
    3.         Do: Doevents: Loop until wb.busy = false
    4.         debug.print "Done"
    5.     End Sub
    6.  
    7.     Public Sub thread2()
    8.         WB2.Navigate "http://www.google.ca"
    9.         Do: Doevents: Loop until wb2.busy = false
    10.         debug.print "Done"
    11.     End Sub
    12.  
    13.     Public Sub AllThread()
    14.         'Combine the two subs in one sub so they can be
    15.         'fired at once
    16.         Me.thread1()
    17.         Me.thread2()
    18.     End Sub
    19.  
    20.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    21.         Dim thrd As Threading.Thread
    22.         thrd = New Threading.Thread(AddressOf AllThread)
    23.         thrd.Start()
    24.  
    25.     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?

  2. #2
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963
    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:
    1. Public Sub thread1()
    2.         WB.Navigate "http://www.google.ca"
    3.         Do: Loop until wb.busy = false
    4.         debug.print "Done"
    5.     End Sub
    6.  
    7.     Public Sub thread2()
    8.         WB2.Navigate "http://www.google.ca"
    9.         Do: Loop until wb2.busy = false
    10.         debug.print "Done"
    11.     End Sub
    12.  
    13.     Public Sub AllThread()
    14.         'thread2 would still have to wait for thread1 to finish.
    15.         'so this procedure is useless. I make two threads instead.
    16.         'Me.thread1()
    17.         'Me.thread2()
    18.     End Sub
    19.  
    20.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    21.         Dim thrd1 As Threading.Thread
    22.         Dim thrd2 As Threading.Thread
    23.         Set thrd1 = New Threading.Thread(AddressOf thread1)
    24.         Set thrd2 = New Threading.Thread(AddressOf thread2)
    25.         thrd1.Start()
    26.         thrd2.Start()
    27.     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

  3. #3
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    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

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269
    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
  •  



Click Here to Expand Forum to Full Width