Which is the correct way to wait for a Thread.finalization and keep my application responsive

前端 未结 5 1324
陌清茗
陌清茗 2021-02-07 18:02

Actually i am using this code and works ok, but i \'am wondering if is the correct way.

  while WaitForSingleObject(MyThread.Handle, 0) = WAIT_TIMEOUT do
    App         


        
5条回答
  •  既然无缘
    2021-02-07 19:01

    I agree with Mason Wheeler's remark, the main thread is best left to do its job, but I would suggest using the OnTerminate event on the thread. It is more 'Delphi natural' and the internal logic does the PostMessage bit for you. Since TThread is not a component, you can't view it in the object inspector and have to write and attach an event handler yourself. It gets called (in the main thread!) after the thread has completed/terminated.

提交回复
热议问题