title: How to use Application.Exit Event in WPF?
body: <p>I need to delete some certain files, then user closes program in WPF. So I tried MDSN code from here <a href="http://msdn.microsoft.com/en-us/library/system.windows.application.exit.aspx">http://msdn.microsoft.com/en-us/library/system.windows.application.exit.aspx</a> this way:</p>
  
  <p>this code located here <code>App.xml.cs</code></p>
  
  <pre><code>public partial class App : Application
  {
   void App_Exit(object sender, ExitEventArgs e)
      {
         MessageBox.Show("File deleted");
          var systemPath = System.Environment.GetFolderPath(
                                    Environment.SpecialFolder.CommonApplicationData);
  
                  var _directoryName1 = Path.Combine(systemPath, "RadiolocationQ");
                  var temp_file = Path.Combine(_directoryName1, "temp.ini");
  
                  if (File.Exists(temp1_file))
                  {
                      File.Delete(temp1_file);
                  }
  
      }
  
  }
  
  // App.xaml
  &lt;Application x:Class="ModernUIApp1.App"
               xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
               xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
               StartupUri="MainWindow.xaml"
               ShutdownMode="OnExplicitShutdown"
               Exit="App_Exit"&gt;
      &lt;Application.Resources&gt;
  </code></pre>
  
  <p>First of all it doesn't delete files, secondly this program stays in the process after I pushed exit button( this is really strange). This code don't give any errors. And finally it doesn't show <code>MessageBox</code> So anything wrong here?</p>
  
  <p>I think he just  can`t find this function.</p>