Microsoft KB Archive/306394

= How to determine when a shelled process ends in Visual Basic .NET or in Visual Basic 2005 =

Article ID: 306394

Article Last Modified on 12/6/2006

-

APPLIES TO


 * Microsoft Visual Basic 2005
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition

-



This article was previously published under Q306394





For a Microsoft Visual C# .NET version of this article, see 304032.

For a Microsoft Visual C++ .NET version of this article, see 307011.



For a Microsoft Visual Basic 6.0 version of this article, see 129796.

IN THIS TASK
SUMMARY
 * Requirements
 * Create the Sample



SUMMARY
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.

back to the top

Requirements

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

back to the top

Create the Sample
 Create a new Visual Basic .NET or Visual Basic 2005 Windows Application project. Form1 is created by default.  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 = &quot;notepad.exe&quot; p.Start   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(&quot;Notepad was closed&quot;) End Sub   Add the following declaration to the Form1 class to declare your process variable: Dim WithEvents p As Process  Press F5 to run the application. The application should start, along with an instance of Notepad. Close Notepad. Note that the Exited event fires, which causes a message box to appear.</li></ol>

back to the top

Keywords: kbvs2005applies kbvs2005swept kbdiagnostics kbhowtomaster KB306394

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.