Close Method

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

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

.NET Framework
Available since 1.1
Return to top
© 2015 Microsoft