Search code examples
multithreadingdelphi-prismoxygene

Can a suspended thread be aborted?


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

I tried to ABORT the thread and I got a runtime error message saying that the thread is suspended and it can't be aborted. I've looked for 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?


Solution

  • After I resumed the suspended thread, I was able to abort the thread;

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