My WPF 4.0 GUI (C # .Net 4.0) with GUI works with a SQL Server database. Each time I run my application, it creates a connection to SQL Server through the ADO.NET Entity Framework, and if SQL Server is unavailable, it throws an exception and displays a MessageBox with a notification.
Now I want the application to close after the user has read this message. I found three ways to do this:
Process.GetCurrentProcess().Kill();
or
this.Shutdown();
or
System.Environment.Exit(0);
They all work fine and do what I need to do - close the application and kill the application process in the Windows task manager.
I want to know:
- What is the difference between the two?
- Which way will close my application faster?
- Which way to close the application should be used?
- Is
Application.Current.Shutdown() and this.Shutdown() the same way to close the application?
Or maybe there is another, more appropriate way to close the WPF GUI application?
Application.Exit() does not work for me, as I get an error:
The ' System.Windows.Application.Exit ' event can only be displayed on the left side + + or - =
Thank.
c # database exception-handling wpf
Mike B. Oct 07 '10 at 10:44 2010-10-07 10:44
source share