Can interrupted threads be interrupted?

I created a thread and this thread can be paused. So how do I kill or terminate a suspended thread?

I tried the ABORT thread and I got a runtime error message stating that the thread was paused and could not be interrupted. I was looking for a terminate method or something similar and it doesn't seem to exist.

 myThread := new Thread(@BigLoop); myThread.Start; myThread.Suspend; myThread.Abort; <<<===exception is raised. 

So how do you kill or terminate a suspended thread?

+4
source share
2 answers

After I resumed the paused thread, I was able to interrupt the thread;

 myThread := new Thread(@BigLoop); myThread.Start; myThread.Suspend; if MyThread.ThreadState = ThreadState.Suspended then myThread.Resume; myThread.Abort; 
+1
source

Note that it is not practical to use an interrupt. A better solution would be to use waithandle (autoresetevent / manualresetevent) to notify the thread that it should stop working. Remember that "Abort" does not work on anything that invokes native code, such as com or pinvoke.

0
source

All Articles