Is it necessary to explicitly stop all threads prior to exiting a Win32 application?

后端 未结 5 1928
[愿得一人]
[愿得一人] 2020-12-09 20:19

I have a Win32 native VC++ application that upon entering WinMain() starts a separate thread, then does some useful job while that other thread is running, then

5条回答
  •  情书的邮戳
    2020-12-09 20:57

    I think you can first close all your windows(so the user won't see your application), and then set a flag for exit, your thread should check the flag periodicly, and once found set, the thread should return.

    after set the flag, your main thread could call ::WaitForSingleObject() or ::WaitForMultipleObjects() for a while (say, three seconds), if the thread(s) not return, just kill them by ::TerminateThread().

提交回复
热议问题