Multiple choice technology web technology

Which of the following can be used to stop a thread?

  1. Thread.Interrupt()

  2. Thread.Abort()

  3. Both A) and B)

  4. None of the Above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Thread.Interrupt() causes a thread to throw ThreadInterruptedException when it enters a wait state, while Thread.Abort() raises ThreadAbortException to terminate the thread. Both methods can stop thread execution, though Abort() is deprecated in modern .NET due to potential data corruption.

AI explanation

In .NET threading, Thread.Abort() forcibly terminates a thread by raising a ThreadAbortException in it, which (unless caught and suppressed) unwinds and ends the thread — a direct, if dangerous and now-deprecated, way to stop it. Thread.Interrupt() is subtly different: it only wakes a thread that is blocked in a wait/sleep/join state by throwing a ThreadInterruptedException at that point; if unhandled, this exception also terminates the thread, but Interrupt() does nothing to a thread that's actively running (non-blocked) code. Because both methods can, in the right circumstances, result in a thread ending, introductory-level material often lists "Both A and B" as usable ways to stop a thread, which is what's marked here.