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?
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?
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.
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.
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.