.NET and Threads

cis4life

New member
Joined
Feb 21, 2007
Messages
4
Programming Experience
Beginner
Hi,
I have a quick question about threads. I have a function that I wrote that is assigned to a threadjob. (Say Hello World Function) My question is, If I create a thread dynamically and have it assigned to a thread job (with the hello world function) once I start the thread and the hello world function fully runs (no while loops, just HELLO WORLD), my question is... Once the hello world function finishes, is the thread considered complete and deletes itself? If not, how do you delete a thread dynamically once its assigned function is complete?
Thanks,
Cedric
 
If Your function is called HelloWorld, then first of all change it to
VB.NET:
HelloWorld(Byval State as Object)

Then to call it, use

VB.NET:
 ThreadPool.QueueUserWorkItem(new WaitCallBack(AddressOf HelloWorld))
 
Ok,

so .NET does it own deletion of threads once the thread's thread jobs function is compelete. Correct? I just want to make sure I understand this methodology.
 
also,

Does the above hold true in both framework 1.1 AND 2.0

Thanks and sorry for the newbish question. Just this is my first time really dealing with threads.

Thanks,
Cedric
 
yep.. that's it..

Ensure that your Work function doesnt throw any exceptions - it kills the entire app..

Oh, and by default the ThreadPool has 25 worker threads. This tripped me up recently in a networking app; just couldnt figure out why I couldnt establish more than 12 working pairs..
 
Thanks a million,

I'm glad you all were able to clear this up for me, I have my app working, and its working great. I just didn't want threads not needed hanging around eating resources and eventaully kill the system.

Cedric
 
Back
Top