Catch Windows terminal closing on running process

前端 未结 3 1350
旧巷少年郎
旧巷少年郎 2020-12-20 03:26

In a command prompt window, I have a running process. While the process is still executing, I click the (red) \'X\' in the corner of the command prompt window. The command p

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-20 04:02

    The equivalent of SIGHUP is provided through the callback you register with SetConsoleCtrlHandler. Your callback function will be called on an arbitrary threadpool thread with dwCtrlType = CTRL_CLOSE_EVENT. You've got 5 seconds to clean-up, you cannot cancel the close.

    Sample code is available in this MSDN article

提交回复
热议问题