c# - Right way to close WPF GUI application: GetCurrentProcess().Kill(), Environment.Exit(0) or this.Shutdown() -


my gui desktop-based wpf 4.0 (c# .net 4.0) program works sql server database. each time when run application creates connection sql server via ado.net entity framework , if sql server not reachable throws exception , shows messagebox notification.

now want after user read message application shut down. found 3 ways this:

process.getcurrentprocess().kill(); 

or

this.shutdown(); // application.current.shutdown() 

or

system.environment.exit(0); 

all of them work fine , need — close application , kill application's process in windows task manager.

i want know:

  1. what difference between them?
  2. which way close application faster?
  3. which way close application should use?
  4. is application.current.shutdown() , this.shutdown() same way close application?

or maybe there another, more suitable, way close wpf gui application?

application.exit() doesn't work me error:

the event 'system.windows.application.exit' can appear on left-hand side of += or -=

thanks.

application.current.shutdown() proper way shutdown application. because fire exit events can handle more

process.getcurrentprocess().kill() should used when want kill application. more

ad1. nature of methods totally different. shutdown process can paused end operations, kill force application close.

ad2. kill() fastest way, kernel panic.

ad3. shutdown because fires close event

ad4. depend this is.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -