This sort of thing is one of the logistical reasons why Abort
is deprecated. First and foremost, do not use Thread.Abort()
to cancel or stop a thread if at all possible. Abort()
should only be used to forcefully kill a thread that is not responding to more peaceful requests to stop in a timely fashion.
That being said, you need to provide a shared cancellation indicator that one thread sets and waits while the other thread periodically checks and gracefully exits. .NET 4 includes a structure designed specifically for this purpose, the CancellationToken
.