Microsoft small business knowledge base

Article ID: 306394 - Last Review: February 27, 2014 - Revision: 2.3

This article was previously published under Q306394
This article has been archived. It is offered "as is" and will no longer be updated.

On This Page


This article demonstrates how to use the Process object to start another process and receive a notification after that process has exited. The Process object, which is located in the System.Diagnostics namespace, exposes the Exited event. By handling this event, you are notified when the process that you launch has exited. Because you are using an event to accomplish this task, this notification process is asynchronous.


  • Visual Studio .NET or Visual Studio 2005
  • Visual Basic .NET or Visual Basic 2005 Language Compiler

Create the Sample

  1. Create a new Visual Basic .NET or Visual Basic 2005 Windows Application project. Form1 is created by default.
  2. Double-click Form1, and add the following code to the Form1 Load event:
            p = New Process()
            ' Handle the Exited event that the Process class fires.
            AddHandler p.Exited, AddressOf p_Exited
            p.EnableRaisingEvents = True
            p.SynchronizingObject = Me
            p.StartInfo.FileName = "notepad.exe"
  3. Below the Form1_Load method, add another method that will handle the Exited event:
        Private Sub p_Exited(ByVal sender As Object, ByVal e As System.EventArgs)
            MessageBox.Show("Notepad was closed")
        End Sub
  4. Add the following declaration to the Form1 class to declare your process variable:
        Dim WithEvents p As Process
  5. Press F5 to run the application. The application should start, along with an instance of Notepad.
  6. Close Notepad. Note that the Exited event fires, which causes a message box to appear.

  • Microsoft Visual Basic 2005
  • Microsoft Visual Basic .NET 2003 Standard Edition
  • Microsoft Visual Basic .NET 2002 Standard Edition
kbnosurvey kbarchive kbvs2005applies kbvs2005swept kbdiagnostics kbhowtomaster KB306394
Additional support options
Ask The Microsoft Small Business Support Community
Contact Microsoft Small Business Support
Find Microsoft Small Business Support Certified Partner
Find a Microsoft Store For In-Person Small Business Support