0

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?

2
  • Please provide some details on "get information on them". Commented Oct 26, 2008 at 21:44
  • Well I have thread starting. However i need thread management as in the ability to talk to a thread. kill it, etc. pastebin.com/m11238dcf my starting code here. Commented Oct 26, 2008 at 21:57

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

1 Comment

Works perfect Im sure with a little bit more i can talk to them. Was exactly what iam looking for.
0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.