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. what is the differcence between close and dispose with Process instance?

what is the differcence between close and dispose with Process instance?

Scheduled Pinned Locked Moved C#
questiontutorialannouncementlearning
5 Posts 3 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.
  • F Offline
    F Offline
    fu0
    wrote on last edited by
    #1

    here is the code: Process p = Process.GetProcessByID(); ... p.close(); p.dispose(); i use close() and dispose() both to release resource.is it correct ? what is the difference between them ? and in this code: Process[] p = Process.GetProcessesByName(); How to release the resource properly ?

    H A 2 Replies Last reply
    0
    • F fu0

      here is the code: Process p = Process.GetProcessByID(); ... p.close(); p.dispose(); i use close() and dispose() both to release resource.is it correct ? what is the difference between them ? and in this code: Process[] p = Process.GetProcessesByName(); How to release the resource properly ?

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      Looking at the IL (Intermediate Language) for the Process class reveals that calling Dispose explicitly calls Close. If you don't call either and the destructor calls Dispose, then the process handle is freed but other native resources are not ( memory leak! :eek: ). Calling Close is sufficient, but it never hurts to call Dispose either. :)

      Microsoft MVP, Visual C# My Articles

      F 1 Reply Last reply
      0
      • F fu0

        here is the code: Process p = Process.GetProcessByID(); ... p.close(); p.dispose(); i use close() and dispose() both to release resource.is it correct ? what is the difference between them ? and in this code: Process[] p = Process.GetProcessesByName(); How to release the resource properly ?

        A Offline
        A Offline
        Alvaro Mendez
        wrote on last edited by
        #3

        Here's a tip, use a using block to make it both easier and safer to release Disposable resources:

        using (Process p = Process.GetProcessByID())
        {
        ...
        }

        No need to worry about calling Dispose (or Close). :) Regards, Alvaro


        Give a man a fish, he owes you one fish. Teach a man to fish, you give up your monopoly on fisheries.

        1 Reply Last reply
        0
        • H Heath Stewart

          Looking at the IL (Intermediate Language) for the Process class reveals that calling Dispose explicitly calls Close. If you don't call either and the destructor calls Dispose, then the process handle is freed but other native resources are not ( memory leak! :eek: ). Calling Close is sufficient, but it never hurts to call Dispose either. :)

          Microsoft MVP, Visual C# My Articles

          F Offline
          F Offline
          fu0
          wrote on last edited by
          #4

          Thanks! Looking at the IL (Intermediate Language) for the Process class reveals that calling Dispose explicitly calls Close where can i find the IL help ?

          H 1 Reply Last reply
          0
          • F fu0

            Thanks! Looking at the IL (Intermediate Language) for the Process class reveals that calling Dispose explicitly calls Close where can i find the IL help ?

            H Offline
            H Offline
            Heath Stewart
            wrote on last edited by
            #5

            It's not "help" - it's the intermediate language contained in the modules that are embedded in assemblies - the very heart of the Common Language Infrastructure (CLI) that makes .NET possible. You can use the IL Disassembler (ildasm.exe) that ships with the .NET Framework SDK, in the SDK's bin directory. Documentation about the IL instruction codes can be found in the .NET Framework SDK.

            Microsoft MVP, Visual C# My Articles

            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