My GUI desktop-based WPF 4.0 (C# .Net 4.0) program works with SQL Server database. Each time when I run my application it creates a connection to SQL Server via ADO.NET Entity Framework and if SQL Server is not reachable it throws an exception and shows MessageBox
with notification.
Now I want that after user read this message application will shut down. I found three ways to do this:
Process.GetCurrentProcess().Kill();
or
this.Shutdown(); // Application.Current.Shutdown()
or
System.Environment.Exit(0);
All of them work fine and do what I need — close application and kill application's process in Windows Task Manager.
I want to know:
- What is the difference between them?
- Which way will close my application faster?
- Which way to close application should I use?
- Is
Application.Current.Shutdown()
and this.Shutdown()
the same way to close application?
Or maybe there is another, more suitable, way to close a WPF GUI application?
Application.Exit()
doesn't work for me as I get the error:
The event 'System.Windows.Application.Exit
' can only appear on the left-hand side of += or -=
Thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…