Process.OnExited Method ()

 

Raises the Exited event.

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

Protected Sub OnExited

OnExited is the API method that raises the Exited event. Calling OnExited causes the Exited event to occur and is the only way to raise the event using the Process component. OnExited is primarily used when deriving classes from the component.

As an alternative to OnExited, you can write your own event handler. You create your own event handler delegate and your own event-handling method.

System_CAPS_noteNote

If you are using the Visual Studio environment, an event handler delegate (AddOnExited) and an event-handling method (Process1_Exited) are created for you when you drag a Process component onto a form and double-click the icon. The code you create to run when the Exited event occurs is entered into the Process1_Exited procedure. You do not need to create the OnExited member, because it is implemented for you.

Raising an event invokes the event handler through a delegate. For an overview, see Handling and Raising Events.

The following example shows how to use the OnExited method in a derived class.

Imports System
Imports System.Diagnostics


Class MyProcess
    Inherits Process

    Public Sub [Stop]() 
        Me.CloseMainWindow()
        Me.Close()
        OnExited()

    End Sub 'StopStop
End Class

Class StartNotePad


    Public Shared Sub Main(ByVal args() As String) 
        Dim p As New MyProcess()
        p.StartInfo.FileName = "notepad.exe"
        p.EnableRaisingEvents = True
        AddHandler p.Exited, AddressOf myProcess_HasExited
        p.Start()
        p.WaitForInputIdle()
        p.Stop()

    End Sub

    Private Shared Sub myProcess_HasExited(ByVal sender As Object, ByVal e As System.EventArgs) 
        Console.WriteLine("Process has exited.")

    End Sub 'myProcess_HasExited
End Class

LinkDemand

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
Show: