Reputation: 83254
I have a WPF application, which in the case of unhandled exception, I want to
For the second purpose, I can easily listen to the AppDomain.CurrentDomain.UnhandledException
event and then restart the same app using the Process.Start
.
But for the first purpose, I that after the exception occurs, the application will freeze for quite a while before finally going away. I try to speed up the process by putting in the
Application.Current.Shutdown();
And yet, it still takes quite a while for the program to freeze and then only finally shut down.
Why is this the case?
And how I can make the old application shut down immediately? An unhandled exception in my application is already bad enough, I don't need the dying application to linger long enough and to embarrass me.
Here's the minimum sample code that reproduces the problem:
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
DispatcherUnhandledException += CurrentApplicationOnDispatcherUnhandledException;
}
private void CurrentApplicationOnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
}
private void CurrentDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Application.Current.Shutdown();
}
}
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void button_Click(object sender, RoutedEventArgs e)
{
throw new NotFiniteNumberException();
}
}
Upvotes: 1
Views: 588