Handle a WPF Exit Event

狂风中的少年 提交于 2019-11-29 05:45:44

You can hook the event Closing on your main window like this -

<Window Closing="Window_Closing">

And in your event set the e.Cancel to true to stop the window from closing. In your case you can maintain some field which will be set once you get notification from client that he's done with cleanUp and its safe now to close the window. Simply set that value to e.Cancel

private void Window_Closing(object sender, CancelEventArgs e)
{
   e.Cancel = true;
}

If you want stop the operating system being shut down, or at least clean up before it does, you need to handle the Application.SessionEnding.

Related: Handling System Shutdown in WPF

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!