Results 1 to 10 of 10

Thread: Multithread problems

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Houston, TX
    Posts
    342

    Question Multithread problems

    I am making a simple program to test threading in VB.NET and I have a process that creates an infinite loop. However, whenever I put the thread to sleep the entire program locks up until the thread is interrupted. Am I doing something wrong?

    Thanks!!

  2. #2
    Hyperactive Member Bananafish's Avatar
    Join Date
    Jan 2001
    Posts
    394
    how are you starting the thread, and how are you suspending it?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Houston, TX
    Posts
    342
    Hopefully I am doing this correctly, but I am using the Thread.Start, and Thread.Sleep methods.

    Code:
    Dim T as Thread
    
    T=New Thread(AddressOf MyThread)
    
    T.Start
    I use T.Sleep(xxx) to halt the thread, but when I do the entire program locks up. I cannot click any buttons, move the form, or even terminate it.

  4. #4
    Hyperactive Member Bananafish's Avatar
    Join Date
    Jan 2001
    Posts
    394
    Try using "T.Suspend" to suspend the thread and "T.Resume" to restart it

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Houston, TX
    Posts
    342
    I have tried that as well and the same thing happens.

    My program is very simple, I have a module that just does an infinite do...loop and 3 buttons (Start, Cancel, Sleep)

    When I start the thread I can cancel it successfully, but if I Sleep (or suspend) I cannot do anything until the sleep timer runs out. I if add another button for Resume I cannot click it when the thread is suspended.

  6. #6
    Hyperactive Member Bananafish's Avatar
    Join Date
    Jan 2001
    Posts
    394
    ok, ive been playing with this, and it appears ok. This is what I have done.

    a)
    Dim ts As New ThreadStart(AddressOf Routine1)
    t = New Thread(ts)
    t.Start()

    t is declared as a global variable (ie, Public t As Thread)

    b) Routine1 is made up of 3 messagebox messages...

    c) I have a button to suspend that does a
    T.Suspend

    and one to resume that does a T.Resume

    When I start the thread - I get the first message box
    If I then press the suspend button, and press the ok in the message box - the 2nd message box doesnt appear until I press the resume button...

  7. #7
    Hyperactive Member Bananafish's Avatar
    Join Date
    Jan 2001
    Posts
    394
    If you wanted it on one line you could do,

    T=New Thread(New ThreadStart(AddressOf MyThread))

    btw - how do you get the code block to display like that in your first message?

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Houston, TX
    Posts
    342
    You can use tags like
    Code:
     "CODE" VB Code Here!  "/CODE"
    Don't use quotes when you use this, you need to use [] instead.
    Last edited by MagellanTX; Nov 27th, 2001 at 12:15 PM.

  9. #9
    Hyperactive Member Bananafish's Avatar
    Join Date
    Jan 2001
    Posts
    394
    Code:
     Thanks

  10. #10
    Fanatic Member Kings's Avatar
    Join Date
    Aug 2001
    Posts
    673
    you can also use the [vbcode] & [/vbcode] tags
    K i n g s

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