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. How to dispose all resources after closing the application ?

How to dispose all resources after closing the application ?

Scheduled Pinned Locked Moved C#
csharpvisual-studiotutorialquestion
15 Posts 4 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.
  • T Offline
    T Offline
    taibc
    wrote on last edited by
    #1

    Hi everyone, My application was written in Visual Studio 2010. After closing my application, there is still a running process that showed in the Task Manager. Do you know, how to dispose all resources after I close my C# application ? Thanks and regards, Tai

    L J 2 Replies Last reply
    0
    • T taibc

      Hi everyone, My application was written in Visual Studio 2010. After closing my application, there is still a running process that showed in the Task Manager. Do you know, how to dispose all resources after I close my C# application ? Thanks and regards, Tai

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

      taibc wrote:

      After closing my application, there is still a running process that showed in the Task Manager.
       
      Do you know, how to dispose all resources after I close my C# application ?

      All .NET objects will be disposed of by the runtime. Did you launch a (non-background) thread?

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

      T 1 Reply Last reply
      0
      • L Lost User

        taibc wrote:

        After closing my application, there is still a running process that showed in the Task Manager.
         
        Do you know, how to dispose all resources after I close my C# application ?

        All .NET objects will be disposed of by the runtime. Did you launch a (non-background) thread?

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

        T Offline
        T Offline
        taibc
        wrote on last edited by
        #3

        Yes. I found out a way to do that by use the statement: Process.GetCurrentProcess().Kill(); Thanks and kind regards,

        L D 3 Replies Last reply
        0
        • T taibc

          Yes. I found out a way to do that by use the statement: Process.GetCurrentProcess().Kill(); Thanks and kind regards,

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

          taibc wrote:

          Process.GetCurrentProcess().Kill();

          Yep.... that will work.... if you do not want to do it correctly.

          1 Reply Last reply
          0
          • T taibc

            Yes. I found out a way to do that by use the statement: Process.GetCurrentProcess().Kill(); Thanks and kind regards,

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            Actually, that'll leak resources, not close them.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak

            J 1 Reply Last reply
            0
            • T taibc

              Yes. I found out a way to do that by use the statement: Process.GetCurrentProcess().Kill(); Thanks and kind regards,

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

              taibc wrote:

              I found out a way to do that by use the statement:Process.GetCurrentProcess().Kill();

              There's no book that recommend thus. It might "feel" as a fast way to exit the app, but as you noticed, it doesn't exit nicely. You might wanna research the difference between foreground and background-threads. I'll bet one of them is still running.

              Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

              1 Reply Last reply
              0
              • D Dave Kreskowiak

                Actually, that'll leak resources, not close them.

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak

                J Offline
                J Offline
                jschell
                wrote on last edited by
                #7

                Dave Kreskowiak wrote:

                Actually, that'll leak resources, not close them.

                What resource do you think will be leaked after the Process exits?

                D 1 Reply Last reply
                0
                • T taibc

                  Hi everyone, My application was written in Visual Studio 2010. After closing my application, there is still a running process that showed in the Task Manager. Do you know, how to dispose all resources after I close my C# application ? Thanks and regards, Tai

                  J Offline
                  J Offline
                  jschell
                  wrote on last edited by
                  #8

                  taibc wrote:

                  Do you know, how to dispose all resources after I close my C# application ?

                  Wrong question. Presumably your application only has one process - if not then you must have started the other processes so stopping them is also required. But excluding that then if your application (process) is still running after you "close" it then that means you started a thread that continues to run. So the solution is that when you "close" it that you must terminate the threads that you started. And the terminology is not apt since it isn't a matter of "resources" - it is an application/process which has not terminated. Once the process terminates all of the resources are freed regardless of the action your application took.

                  1 Reply Last reply
                  0
                  • J jschell

                    Dave Kreskowiak wrote:

                    Actually, that'll leak resources, not close them.

                    What resource do you think will be leaked after the Process exits?

                    D Offline
                    D Offline
                    Dave Kreskowiak
                    wrote on last edited by
                    #9

                    Off the top of my head, anything that holds an unmanaged handle, such as GDI objects: Brush, Pen, Graphics, ... That's by no means a complete list of the stuff that can be orphaned, just a sample.

                    A guide to posting questions on CodeProject[^]
                    Dave Kreskowiak

                    J 1 Reply Last reply
                    0
                    • D Dave Kreskowiak

                      Off the top of my head, anything that holds an unmanaged handle, such as GDI objects: Brush, Pen, Graphics, ... That's by no means a complete list of the stuff that can be orphaned, just a sample.

                      A guide to posting questions on CodeProject[^]
                      Dave Kreskowiak

                      J Offline
                      J Offline
                      jschell
                      wrote on last edited by
                      #10

                      I doubt that a Process will hold on to any of those when the Process exits, regardless of how it exits.

                      D 1 Reply Last reply
                      0
                      • J jschell

                        I doubt that a Process will hold on to any of those when the Process exits, regardless of how it exits.

                        D Offline
                        D Offline
                        Dave Kreskowiak
                        wrote on last edited by
                        #11

                        I wouldn't bet on that - from experience.

                        A guide to posting questions on CodeProject[^]
                        Dave Kreskowiak

                        J 1 Reply Last reply
                        0
                        • D Dave Kreskowiak

                          I wouldn't bet on that - from experience.

                          A guide to posting questions on CodeProject[^]
                          Dave Kreskowiak

                          J Offline
                          J Offline
                          jschell
                          wrote on last edited by
                          #12

                          Dave Kreskowiak wrote:

                          I wouldn't bet on that - from experience.

                          Then it is an OS bug. "•Any resources allocated by the process are freed." http://msdn.microsoft.com/en-us/library/windows/desktop/ms686722(v=vs.85).aspx[^]

                          D 1 Reply Last reply
                          0
                          • J jschell

                            Dave Kreskowiak wrote:

                            I wouldn't bet on that - from experience.

                            Then it is an OS bug. "•Any resources allocated by the process are freed." http://msdn.microsoft.com/en-us/library/windows/desktop/ms686722(v=vs.85).aspx[^]

                            D Offline
                            D Offline
                            Dave Kreskowiak
                            wrote on last edited by
                            #13

                            Maybe not. It may depend on if you run the system out of resources first. My experience was killing a process that leaked handles like crazy. Once you exhaust the handle pool, Windows starts to loose it's mind.

                            A guide to posting questions on CodeProject[^]
                            Dave Kreskowiak

                            J 1 Reply Last reply
                            0
                            • D Dave Kreskowiak

                              Maybe not. It may depend on if you run the system out of resources first. My experience was killing a process that leaked handles like crazy. Once you exhaust the handle pool, Windows starts to loose it's mind.

                              A guide to posting questions on CodeProject[^]
                              Dave Kreskowiak

                              J Offline
                              J Offline
                              jschell
                              wrote on last edited by
                              #14

                              Dave Kreskowiak wrote:

                              Windows starts to loose it's mind.

                              Which version of windows?

                              D 1 Reply Last reply
                              0
                              • J jschell

                                Dave Kreskowiak wrote:

                                Windows starts to loose it's mind.

                                Which version of windows?

                                D Offline
                                D Offline
                                Dave Kreskowiak
                                wrote on last edited by
                                #15

                                XP (any SP version)

                                A guide to posting questions on CodeProject[^]
                                Dave Kreskowiak

                                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