How do I stop a thread before it's finished running?

后端 未结 3 1164
遇见更好的自我
遇见更好的自我 2021-02-06 15:03

I have a thread called TMyThread and I overrode the Execute procedure like this:

 procedure TMyThread.Execute;
 Begin
     repeat
     //Some Work 
     Sleep(50         


        
3条回答
  •  广开言路
    2021-02-06 15:30

    You really are approaching this problem completely wrong. Code your threads to only do work that you want them to do, and then there will be no need to "reach in from the outside" to control them. You feel the need to control this thread from the outside because it's doing something you don't want it to do -- well then why did you code it to do that in the first place?

提交回复
热议问题