Export (0) Print
Expand All

Process.Close Method

Frees all the resources that are associated with this component.

Namespace:  System.Diagnostics
Assembly:  System (in System.dll)

Public Sub Close

The Close method causes the process to stop waiting for exit if it was waiting, closes the process handle, and clears process-specific properties. Close does not close the standard output, input, and error readers and writers in case they are being referenced externally.


The Dispose method calls Close. Placing the Process object in a using block disposes of resources without the need to call Close.

The following example starts an instance of Notepad. It then retrieves the physical memory usage of the associated process at 2-second intervals for a maximum of 10 seconds. The example detects whether the process exits before 10 seconds have elapsed. The example closes the process if it is still running after 10 seconds.

Imports System
Imports System.Diagnostics
Imports System.Threading

Namespace Process_Sample
   Class MyProcessClass

      Public Shared Sub Main()

            Dim myProcess As Process
            myProcess = Process.Start("Notepad.exe")
            ' Display physical memory usage 5 times at intervals of 2 seconds. 
            Dim i As Integer 
            For i = 0 To 4
               If not myProcess.HasExited Then 

                  ' Discard cached information about the process.
                  ' Print working set to console.
                  Console.WriteLine("Physical Memory Usage: " + _
                  ' Wait 2 seconds.
                  Exit For 
               End If 

            Next i

           ' Close process by sending a close message to its main window.
           ' Free resources associated with process.

         Catch e As Exception
            Console.WriteLine("The following exception was raised: ")
         End Try 
      End Sub 'Main
   End Class 'MyProcessClass
End Namespace 'Process_Sample

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

  • LinkDemand 

    for full trust for the immediate caller. This member cannot be used by partially trusted code.

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft