How to use Application.Exit Event in WPF?

后端 未结 5 749
没有蜡笔的小新
没有蜡笔的小新 2020-12-05 14:29

I need to delete some certain files, then user closes program in WPF. So I tried MDSN code from here http://msdn.microsoft.com/en-us/library/system.windows.application.exit.

5条回答
  •  自闭症患者
    2020-12-05 15:22

    It's quite simple:

    Add "Exit" property to the application tag

    
    
    

    and handle it in the "code behind"

    private void Application_Exit(object sender, ExitEventArgs e)
    {
        // Perform tasks at application exit
    }
    

    The Exit event is fired when the application is shutting down or the Windows session is ending. It is fired after the SessionEnding event. You cannot cancel the Exit event.

提交回复
热议问题