我的基于GUI桌面的WPF 4.0(C#.NET4.0)程序可以与SQL Server数据库配合使用.每次我运行应用程序时,它都会通过ADO.NET实体框架创建到SQL Server的连接,如果无法访问SQL Server,它会抛出异常,并显示MessageBox
并发出通知.
现在我希望在用户阅读此消息后,应用程序将关闭.我找到了三种方法:
Process.GetCurrentProcess().Kill();
或
this.Shutdown(); // Application.Current.Shutdown()
或
System.Environment.Exit(0);
All of them w或k fine and do what I need — close application and kill application's process in Windows Task Manager.
我想知道:
- 它们之间有什么不同?
- 哪种方式可以更快地关闭我的应用程序?
- 我应该使用哪种方式关闭应用程序?
-
Application.Current.Shutdown()
和this.Shutdown()
是关闭应用程序的相同方式吗?
Or maybe there is another, m或e suitable, way to close a WPF GUI application?
Application.Exit()
doesn't w或k f或 me as I get the err或:
The event '
System.Windows.Application.Exit
' can only appear on the left-hand side of += 或 -=
谢谢