This documentation is archived and is not being maintained.

Process.Close Method

Frees all the resources that are associated with this component.

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

public void Close ()
public void Close ()
public function 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.

using System;
using System.Diagnostics;
using System.Threading;

namespace Process_Sample
   class MyProcessClass
      public static void Main()
            Process myProcess;
            myProcess = Process.Start("Notepad.exe");
            // Display physical memory usage 5 times at intervals of 2 seconds.
            for (int i = 0;i < 5; i++)
               if (!myProcess.HasExited)
                   // Discard cached information about the process.
                   // Print working set to console.
                   Console.WriteLine("Physical Memory Usage: " 
                                        + myProcess.WorkingSet.ToString());
                   // Wait 2 seconds.
               else {

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

         catch(Exception e)
            Console.WriteLine("The following exception was raised: ");

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0