Click to See Complete Forum and Search --> : multithreading question on vb.net


cgchris99
April 11th, 2002, 02:54 PM
Ok, I have been reading everything I can find on multithreaded apps in VB.net
I am new to vb.net but have worked with vb6.

My app will start 4 or 5 threads. Two of them will be high priority. The others can run a little slower.
In testing, I have 4 threads starting. And I have a button on my form to stop the threads.
So I call mythread.suspend()

When I check the states of the threads two of them are suspended and two are threadstate=96.
Someone mentioned this was a combination of Suspended and WaitSleepJoin.

1) This is where I am getting lost. If I called Suspend. Where did the Waitsleepjoin come from.

2) Also, when you call suspend, where does the code actually stop? Is it random, at the start of my loop or what?

3) If I need some threads to be idle until a certain condtion, how do I do this? with suspend or other?

4) I have been reading a bunch. Is there any documention on threads that say, when you want 'A' do this, when you want 'B' do this.

Thanks for any help you can give.

Craig Gemmill
April 11th, 2002, 03:22 PM
When you call suspend you are actually suspending not stoping the thread. In the .Net beta 2 you could use thread.stop but it was removed because it was not a healthy way of stopping execution of code. The best way to stop a thread is to have the thread reference a boolean variable, and when that variable is false then stop thread execution. ill post an example later.

cgchris99
April 11th, 2002, 03:30 PM
That is what I want. I want to suspend the thread and then resume. Well, when I tried that. I ended up with a couple threads that did not equal ThreadState=Suspended.

But this doesn't answer where a thread actually suspends.

Or are you supposed to put the suspend code in the thread and have it activate via a global variable or something?

Thanks