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

前端 未结 5 1326
陌清茗
陌清茗 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:04

    It looks correct (if correct means it do the work). What I would change is to wait for a bit more time (50ms looks good to maintain the application responsive) while not eating CPU.

    while WaitForSingleObject(MyThread.Handle, 50) = WAIT_TIMEOUT do
      Application.ProcessMessages;
    ShowMessage('i am done');
    

    Sure there are other ways to do it... but I usually apply one of the main engineering principles:

    if it works, don't touch it!

提交回复
热议问题