Chris
Chris

Reputation: 3

Threading aborted state problem

I have a library to manage the threads built on .NET 3.5. When I am trying to upgrade it to .NET 4.0 some of the unit tests failed according to the Thread.Abort method.

In brief of those unit tests, the thread states are tracked from creation to stopped. When the thread is being aborted, those unit tests track the states from Running -> AbortRequested -> Aborted -> Stopped. The sequence is working exactly identical on .NET 3.5 using VS2008 or VS2010. Until I upgrade it to .NET 4.0 on VS2010, the unit tests fail. The result is the thread remains in Aborted state.

I have checked MSDN about the Thread.Abort and here is the words, "After Abort is invoked on a thread, the state of the thread includes AbortRequested. After the thread has terminated as a result of a successful call to Abort, the state of the thread is changed to Stopped."

Is there anyone having the same problem? Is the .NET 4.0 threading behavior correct? If the thread stays on Aborted, does it have any impact?

Upvotes: 0

Views: 247

Answers (1)

Hans Passant
Hans Passant

Reputation: 942109

I repro. Go ahead and assume it is a bug-fix. Having the state going back to Stopped doesn't make much sense.

There's an old feedback report about it here. They acknowledge that the behavior in .NET 2.0 doesn't match the documented behavior but that it was too late to fix the problem. Although closed, I strongly suspect they fixed it for 4.0. Ironically, it looks like the documented behavior was updated in the MSDN Library, now again mismatching the actual behavior.

Upvotes: 3

Related Questions