how to kill a thread gracfully
-
Hi how can i kil thread gracefully in c#1.1
-
Hi how can i kil thread gracefully in c#1.1
The most graceful way is to tell the thread to stop on it's own. If the thread is running an instance method of a class, you could change a proeprty in the class to flag that it's time to stop. Otherwise there is a special exception (don't recall what it's called right now) that you can raise in the thead, that you can initiate from outside the thread and catch inside the thread. That gives the thread a chance to clean up whatever it needs before turning in. -- modified at 9:11 Sunday 8th October, 2006 I was just reading about Monitors, and stumbled upon the Exception that is used to interrupt a thread. The exception is
ThreadInterruptedException
, and is created with theInterrupt
method of theThread
class.--- b { font-weight: normal; }
-
Hi how can i kil thread gracefully in c#1.1