Is it safe to use Process.GetCurrentProcess().Kill() ?
-
Hi, I have developed an application in C# .Net... My requirement is that the application should clean up all the resources that it used and exit when I click on the "Exit" option that I have provided.. But sometimes, when I try to exit the application using "Application.Exit()", the application fails to exit and continues to be listed on the Windows processes in the task manager. I would like to know if I can use Process.GetCurrentProcess().Kill() instead of Application.Exit(). If not, please suggest on what I can do to have the application exit when I want it to... Thanks, ramz_g
-
Hi, I have developed an application in C# .Net... My requirement is that the application should clean up all the resources that it used and exit when I click on the "Exit" option that I have provided.. But sometimes, when I try to exit the application using "Application.Exit()", the application fails to exit and continues to be listed on the Windows processes in the task manager. I would like to know if I can use Process.GetCurrentProcess().Kill() instead of Application.Exit(). If not, please suggest on what I can do to have the application exit when I want it to... Thanks, ramz_g
Think about what you've just asked. Then give the answer you think most appropriate. Have you thought about - God forbid - finding what is still running? The technique is part of the leet skilz called 'debugging' [added] try
Application = null;
Panic, Chaos, Destruction. My work here is done.
modified on Wednesday, October 7, 2009 11:11 AM
-
Hi, I have developed an application in C# .Net... My requirement is that the application should clean up all the resources that it used and exit when I click on the "Exit" option that I have provided.. But sometimes, when I try to exit the application using "Application.Exit()", the application fails to exit and continues to be listed on the Windows processes in the task manager. I would like to know if I can use Process.GetCurrentProcess().Kill() instead of Application.Exit(). If not, please suggest on what I can do to have the application exit when I want it to... Thanks, ramz_g
Obviously it would be potentially dangerous given the function of your application. Imagine if you terminate the process unexpectedly while it is writing to a database or file? You could do damage with this method.
Check out the CodeProject forum Guidelines[^] The original soapbox 1.0 is back![^]
-
Hi, I have developed an application in C# .Net... My requirement is that the application should clean up all the resources that it used and exit when I click on the "Exit" option that I have provided.. But sometimes, when I try to exit the application using "Application.Exit()", the application fails to exit and continues to be listed on the Windows processes in the task manager. I would like to know if I can use Process.GetCurrentProcess().Kill() instead of Application.Exit(). If not, please suggest on what I can do to have the application exit when I want it to... Thanks, ramz_g
then you have either infinitive loop or another thread running. Also when exiting Garbage Collection cleans everything. When using Kill() is only for last resort when programs stopped responding. To prevent that happening, code it so that it will not happen. If you use all data will be lost, so don't use it. Find a bug and fix it
-
Hi, I have developed an application in C# .Net... My requirement is that the application should clean up all the resources that it used and exit when I click on the "Exit" option that I have provided.. But sometimes, when I try to exit the application using "Application.Exit()", the application fails to exit and continues to be listed on the Windows processes in the task manager. I would like to know if I can use Process.GetCurrentProcess().Kill() instead of Application.Exit(). If not, please suggest on what I can do to have the application exit when I want it to... Thanks, ramz_g
Safe? Sure, but stupid. Even Application.Exit() should be unnecessary; I've never used it and I don't see why it would ever be required.
-
Think about what you've just asked. Then give the answer you think most appropriate. Have you thought about - God forbid - finding what is still running? The technique is part of the leet skilz called 'debugging' [added] try
Application = null;
Panic, Chaos, Destruction. My work here is done.
modified on Wednesday, October 7, 2009 11:11 AM
Nagy Vilmos wrote:
Think about what you've just asked. Then give the answer you think most appropriate.
Nah. If we all replied like that, CP would go belly up. :)
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
-
Hi, I have developed an application in C# .Net... My requirement is that the application should clean up all the resources that it used and exit when I click on the "Exit" option that I have provided.. But sometimes, when I try to exit the application using "Application.Exit()", the application fails to exit and continues to be listed on the Windows processes in the task manager. I would like to know if I can use Process.GetCurrentProcess().Kill() instead of Application.Exit(). If not, please suggest on what I can do to have the application exit when I want it to... Thanks, ramz_g