Re: Blocked threads vs Thread.Interrupt

From: TT \(Tom Tempelaere\) (_N_0SPA|/\|titi_____at_hotmail.com|/\|APS0_N_)
Date: 03/30/04


Date: Tue, 30 Mar 2004 06:55:45 GMT

Hi Dave,

"Dave" <noSpamdlevineNNTP2@wi.rr.com> wrote in message
news:eo20NEfFEHA.2576@TK2MSFTNGP11.phx.gbl...
[...]
> That being said, neither mechanism is the one I currently prefer. When I
> launch a thread I usually have it run in a loop that blocks waiting on
> multiple events; when one occurs it wakes up, does it work, and then goes
> back to sleep. One of those events is a ManualResetEvent which I use as a
> signal to exit the thread. This ensures that everything is synchronized
and
> nothing vital will get interrupted.

This is what I do now.

But if I read correctly, Thread.Interrupt is actually ideal for waiting
situations. If I would make a thread that waits until this or that, then
Thread.Interrupt seems the only way to unblock if you don't have an explicit
shutdown event.

> There are other issues with using an abort that are not obvious. One is
that
> if the thread is currently executing unmanaged then the abort will not
> actually be raised until it transitions back into managed code - this can
be
> an arbitrarily long time.

Thread.Interrupt has the same problem I suppose.

> Make sure that you set all worker threads to background threads to ensure
> your app can exit even if the thread is still running. Or use a threadpool
> thread.
>
> Dave

Thanks,

---
Tom Tempelaere


Relevant Pages

  • Re: Compact framework application loop
    ... I start an new application loop by eg. Application.Run(new SomeFrm); ... and then after some event I want to launch another form in ... You will, of course, have to then use Application.ExitThread() explicitly when it's time to actually exit, but that's simple enough to hook up. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Infinite Loops and Explicit Exits
    ... > CS> One of these proposals relaxes the current restriction that an EXIT ... > termination of the loop is not visible at that point. ... > terminating condition is visible in that context. ... > You now want to allow this remote procedure, ...
    (comp.lang.cobol)
  • Re: Houston-related rants was Re: forced merges/inside lane merges/AASHTO "tapered merges"
    ... >> Are you sure about the North Loop and I-45? ... >> in particular the westbound exit for Fondren/Gessner. ... How could HCTRA put an exit ramp for eastbound ... and the West Houston Center Blvd exit still shows Old Westheimer ...
    (misc.transport.road)
  • Re: Exit Do
    ... I've been instructed by a dot net / asp programmer that Exit Do is ... I am using nested loops and need to exit out of one loop into ... Code Stage B ... likely to lead to bugs and readability problems. ...
    (microsoft.public.scripting.vbscript)
  • Re: Exit Do
    ... I've been instructed by a dot net / asp programmer that Exit Do is ... I am using nested loops and need to exit out of one loop into ... If Some Reason to stop loop then Exit Do ... Code Stage B ...
    (microsoft.public.scripting.vbscript)