title: WPF application OnExit event
body: <p>I have a WPF application with a main Window.</p>
  
  <p>In App.xaml.cs, in the OnExit event, I would like to use a method from my MainWindow code behind...</p>
  
  <pre><code>public partial class App
  {
      private MainWindow _mainWindow;
  
      protected override void OnStartup(StartupEventArgs e)
      {
           _mainWindow = new MainWindow();
          _mainWindow.Show();
  
  
      }
  
      protected override void OnExit(ExitEventArgs e)
      {
          _mainWindow.DoSomething();
      }
  
  }
  </code></pre>
  
  <p>The method :</p>
  
  <pre><code>public void DoSomething()
  {
      myController.Function(
         (sender, e) =&gt;
         {
  
          },
  
         (sender, e) =&gt;
          {
  
          }
          );
   }
  </code></pre>
  
  <p>But I put a breakpoint on the "_mainWindow.DoSomething();" and when I press f11, it doesn't enter into the function and the function does nothing... Am I missing something ?</p>
  
  <p>I'm a beginner, is it possible to do what I need ?</p>
  
  <p>EDIT : post edited</p>