-
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!!
-
how are you starting the thread, and how are you suspending it?
-
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.
-
Try using "T.Suspend" to suspend the thread and "T.Resume" to restart it
-
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.
-
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...
-
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?
-
You can use tags like
Code:
"CODE" VB Code Here! "/CODE"
Don't use quotes when you use this, you need to use [] instead.
-
-
you can also use the [vbcode] & [/vbcode] tags