views:

66

answers:

1

Normally will we interrupt a thread which is in "WaitSleepJoin" state or "Running" state?

+5  A: 

Normally you don't interrupt a thread at all... but if you try to, it won't actually be interrupted until it next blocks. From MSDN:

If this thread is not currently blocked in a wait, sleep, or join state, it will be interrupted when it next begins to block.

ThreadInterruptedException is thrown in the interrupted thread, but not until the thread blocks. If the thread never blocks, the exception is never thrown, and thus the thread might complete without ever being interrupted.

Jon Skeet
Jon please give some example with comment.
An example of what? I can't remember the last time I wanted to interrupt a thread, and it would be pointless without context to be honest. The call itself is simple enough...
Jon Skeet