[The answer to a different question, which was deleted, unfairly.]
Sorry that I'm answering to the deleted question in this unusual way; I can see that the deleted question was important enough. It was a question when you used
Thread.Suspend
and
Thread.Release
.
This is my answer:
The bug in not in the code shown, it is in the code calling those two methods. The message is more than straightforward. This is how the method
Suspend
and
Resume
work: when the status is already suspended, the thread cannot be suspended again, when the status is not suspended, the thread cannot be resumed.
In your comment to the deleted question you said that you resolved the problem. No, you didn't. You have much bigger problem now.
Much more importantly, these two threads are deprecated, because they are really unsafe. In fact, you should never ever use them:
http://msdn.microsoft.com/en-us/library/system.threading.thread.resume(v=vs.110).aspx[
^],
http://msdn.microsoft.com/en-us/library/system.threading.thread.suspend(v=vs.110).aspx[
^].
Probably, you totally ignored the compiler warnings which should be shown on the use of these methods, because they are marked with
Obsolete
attribute. This is not good for you, really bad.
Why these methods are unsafe? This is pretty obvious, but not so easy to explain; as you can see, MSDN documentation does not really explain the background, but I tried to explain it here:
Security on my developed dll[
^].
I explained correct and safe technique of suspending threads in my past answer, after [EDIT]:
thread.suspend, thread.resume methods[
^].
If something is not clear to you, please ask some follow-up question, only never use the unsafe techniques, otherwise you will face really nasty problems which are hard to detect. (Especially of you ignore warnings. :-))
Note: Please, try to put your code sample in your question post, instead of referencing the code sample on a different site; it makes it much harder to read.
—SA