App.Current.Shutdown() works asynchronously. It means that when you invoke this method you are not protected from execution of lines of code which follow the invokation of Shutdown().
So the question is how to block a thread from which App.Current.Shutdown() is invoked?
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
App.Current.Shutdown();
File.WriteAllText(@"..\log.txt", "Info");
}
}
private void App_OnExit(object sender, ExitEventArgs e) {
Thread.Sleep(3500);
}
File.WriteAll will create a new file and write into it "Info" string.