Re: How do I gently terminate a thread???
From: TT \(Tom Tempelaere\) (_N_0SPA|/\|titi_____at_hotmail.com|/\|APS0_N_)
Date: 05/07/04
- Next message: Paul Clement: "Re: Creating OCX files"
- Previous message: RCIC: "XmlSerializer and Chars"
- In reply to: Ryan Gregg: "Re: How do I gently terminate a thread???"
- Next in thread: Bob Rock: "Re: How do I gently terminate a thread???"
- Reply: Bob Rock: "Re: How do I gently terminate a thread???"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 07 May 2004 19:08:08 GMT
Hi,
"Ryan Gregg" <rgregg@wheatlandsystems.com> wrote in message
news:%23gZ3MCFNEHA.1644@TK2MSFTNGP09.phx.gbl...
> Say for instance I have a thread that I fire off that's running some loop
of
> code that's monitoring status or something. I know I could define a
> variable in a shared address space, and have that loop until the variable
> goes false or something, which would then have the thread exit. Is there
a
> way though without using this method to cause a thread to shut down
without
> calling Abort() ?
You could throw an exception that is only caught in the main method of the
your thread, then just return.
Or, if you wait on WaitHandle-s, you join with other threads or you sleep a
lot (Thread.Sleep), you could call Thread.Interrupt. The next wait, join or
sleep on the thread will then throw a ThreadInterruptedException. Beware of
general exception handlers that could catch this exception and ignore it.
The nice thing about Thread.Abort is that it throws a
ThreadAbortedException, which is a special kind of exception. It will be
rethrown when caught until the thread exits, or until you call
Thread.ResetAbort.
Cheers,
--- Tom Tempelaere.
- Next message: Paul Clement: "Re: Creating OCX files"
- Previous message: RCIC: "XmlSerializer and Chars"
- In reply to: Ryan Gregg: "Re: How do I gently terminate a thread???"
- Next in thread: Bob Rock: "Re: How do I gently terminate a thread???"
- Reply: Bob Rock: "Re: How do I gently terminate a thread???"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|