> >What about Thread.Interrupt? Isn't that for waking up a thread that's
> >currently sleeping?
>
> Thread.Interrupt is documented with "...If this thread is not currently
> blocked in a wait, sleep, or join state, it will be interrupted when it
> next begins to block.".
>
> You can use Thread.Interrupt but it is an abnormal termination technique
> and could lead to corrupted invariants, if you're not careful.

Well, actually, it's not a termination technique (as Thread.Abort is),
it's an interruption technique, meant for waking up threads, not for
aborting them. So, it _seems_ to be suitable for this kind of task.

However, if I understand Joe Duffy correctly, the problem is that most
parts of the .NET framework (and, of course, other class libraries and
frameworks) have not been hardened against thread interruptions. So if
a .NET API happens to call WaitOne, Sleep, or something similar, its
invariants may be broken if the thread is interrupted.

And since, in fact, the SetPinState method in Peter Osucha's code is
probably calling methods inside the .NET framework, it's indeed good
advice not to use Thread.Interrupt. Thank you for linking to that
article.

Fabian

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to