views:

205

answers:

5

Im looking to build a thread manager for an application.

I have already started threading and it works entirely fine but I would like to be able to programatically kill them or get information on them.

Does anyone have ideas?

+3  A: 

Just one quick word of warning: don't use Thread.Abort unless you're really shutting down the whole application (or you're calling it from the thread you're aborting, in which case you know what the thread's doing at the time). If you really want to be able to "kill" threads, I'd advise a fairly "soft" kill - setting a flag, and making sure you test that flag regularly from within the thread.

Part of my threading tutorial talks about shutting down threads cleanly - you might find it useful.

Jon Skeet
A: 

Killing threads harshly: not a good idea. You should almost always communicate with a thread (even a simple volatile bit-flag would do), and let the thread commit suicide. Killing it is very risky, and can leave locks on objects etc.

For the more general case - have you heard of parallel extensions? There is a whole new level of threading management planned for .NET 4.0, including parallel LINQ extensions, etc.

Marc Gravell
A: 

Thanks for the recommendations but i dont think either of those are what i am looking for...

Also this is developed in .net 2.0

A: 

You might look at Thread.ThreadState, Thread.Interrupt(), and Thread.Abort() (as Jon Skeet points out, this is not a preferred way to stop a thread).

For a collection of all the threads running in your application, use System.Diagnostics.Process.GetCurrentProcess().Threads.

For more info, you might have a look at this example of a thread monitor.

Jon B
Checking this out right now
Works perfect Im sure with a little bit more i can talk to them.Was exactly what iam looking for.
A: 

Yeah I need to directly reference thread handles the code you guys are pushing are ones you create programatically as a variable. then you can stop or abort

I want a function to loop through specific threads i create. IE A thread manager. Dont get me wrong about I appreciate the help but the abort,interrupt,etc, functions ill need. But its not really what im asking. What i am talking about that is like talking about how my tires can be unscrewed but im asking how to fix the engine. Dont get me wrong abort is how you programatically abort one i got that. ive understood that I can go through a property list. I understand how to abort a thread but its not what im looking for.

I basically need a thread state library and threat communication library. I have tried to obtain this a couple ways but i cannot reference then unless they are global and redimmed in an array. Ive tried collections and some other stuff.

Hope this helps people understand what im really going for. I also still havnt got thread communication going as well. pasted in my comments is a paste bin of my thread starting

I updated my answer with a link to a thread monitor code sample.
Jon B