Threading Question

  • Thread starter Thread starter Ily
  • Start date Start date
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
 
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.
 
Back
Top