Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Is it safe to use Process.GetCurrentProcess().Kill() ?

Is it safe to use Process.GetCurrentProcess().Kill() ?

Scheduled Pinned Locked Moved C#
csharpquestion
7 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    ramz_g
    wrote on last edited by
    #1

    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

    N L S P R 5 Replies Last reply
    0
    • R 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

      N Offline
      N Offline
      Nagy Vilmos
      wrote on last edited by
      #2

      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

      L 1 Reply Last reply
      0
      • R 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

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        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![^]

        1 Reply Last reply
        0
        • R 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

          S Offline
          S Offline
          Saksida Bojan
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • R 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

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • N Nagy Vilmos

              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

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              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!


              1 Reply Last reply
              0
              • R 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

                R Offline
                R Offline
                ramz_g
                wrote on last edited by
                #7

                Hi All, Thanks for all your replies... @Nagy Vilmos, Yes Nagy, I did think about what could be running.. It is just that I was not able to find what was running.. Debugging? Of course.. Anyways, thanks for your reply...

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups