Threading Question

I

Ily

Hi all


I have 2 (simple) questions about threading.

1)How can I get a notifiication that a thread has completed its work?

2)When I try to abort a thread thats currently suspended I get the
following error:

An unhandled exception of type 'System.Threading.ThreadStateException'
occurred in mscorlib.dll

Additional information: Thread is suspended; attempting to abort.

How do I get this thread to abort?

Many thanks
 
G

Guest

1)How can I get a notifiication that a thread has completed its work?

There is nothing built into .net to support this. What I do is launch all
threads via a class that I wrote. Among other things, the class raises a
public event whenever a thread that it launches is completed.
2)When I try to abort a thread thats currently suspended I get the
following error:
An unhandled exception of type 'System.Threading.ThreadStateException'
occurred in mscorlib.dll

From O'Reilly's ".net gotchas" book, we are encouraged to avoid using
IsAlive, ThreadState, Suspend, Resume, ResetAbort, Abort, and, in my opinion,
all other manipulation of running threads. If all you need is to kill
threads in order to terminate your app, then make the threads background
threads. I do this, and for some kinds of threading operations, it is
sufficient. If you need more (maybe you need to close other resources when
the thread terminates), then you need to indicate to your threads that they
should quit by setting a quit flag of some kind, and then program your
threads to periodically examine the flag.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Aborting a suspended thread 2
Threading question 1
stopping threads 2
Help with Threading 3
Int32.Parse calling Thread.Abort? 1
ApplicationContext ThreadSafety 1
Any Threading Gurus out there? 10
Threading a server 8

Top