3

I have WPF application where I have changed the default entry point.

<Application x:Class="FrazerClient.App" Startup="AppStartup">

public void AppStartup(object sender, StartupEventArgs e)
{
    // Does some minor work before an application window opens.
}

The minor work calls this a couple of times:

App.Current.Dispatcher.Invoke((Action)delegate
{
  // Custom dialog window is opened
});

The second time this is called, App.Current becomes null. I am almost positive is has to do with the custom dialog window closing, but not really sure how to prevent the closing of the dialog window from nulling out App.Current when the last window closes.

This also prevents App.Current.Shutdown() from working.

KJSR
  • 1,679
  • 6
  • 28
  • 51
David Bentley
  • 824
  • 1
  • 8
  • 27

2 Answers2

3

Set ShutDownMode to OnExplicitShutdown so that closing the window does not automatically shutdown the application.

You usually do that in the Xaml of the application object

<Application x:Class="FrazerClient.App"
         Startup="AppStartup"
         ShutdownMode="OnExplicitShutdown">
NineBerry
  • 26,306
  • 3
  • 62
  • 93
  • Yeah, I found a couple different ways to do this. My next step is to find a way to implement this into my MVVM DLL Framework now. – David Bentley Aug 01 '19 at 15:25
1

Resolved with this code:

Application.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;

David Bentley
  • 824
  • 1
  • 8
  • 27