Process.OnExited Método

Definición

Genera el evento Exited.Raises the Exited event.

protected:
 void OnExited();
protected void OnExited ();
member this.OnExited : unit -> unit
Protected Sub OnExited ()

Ejemplos

En el ejemplo siguiente se muestra cómo utilizar el OnExited método en una clase derivada.The following example shows how to use the OnExited method in a derived class.

using System;
using System.Diagnostics;

class MyProcess : Process
{
    public void Stop()
    {
        this.CloseMainWindow();
        this.Close();
        OnExited();
    }
}
class StartNotePad
{

    public static void Main(string[] args)
    {
        MyProcess p = new MyProcess();
        p.StartInfo.FileName = "notepad.exe";
        p.EnableRaisingEvents = true;
        p.Exited += new EventHandler(myProcess_HasExited);
        p.Start();
        p.WaitForInputIdle();
        p.Stop();
    }
    private static void myProcess_HasExited(object sender, System.EventArgs e)
    {
        Console.WriteLine("Process has exited.");
    }
}
Imports System.Diagnostics


Class MyProcess
    Inherits Process
    
    Public Sub [Stop]() 
        Me.CloseMainWindow()
        Me.Close()
        OnExited()
    
    End Sub
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
End Class

Comentarios

OnExited es el método de API que genera el Exited evento.OnExited is the API method that raises the Exited event. La llamada a OnExited hace que se Exited produzca el evento y es la única manera de generar el evento mediante el Process componente.Calling OnExited causes the Exited event to occur and is the only way to raise the event using the Process component. OnExited se utiliza principalmente al derivar clases del componente.OnExited is primarily used when deriving classes from the component.

Como alternativa a OnExited , puede escribir su propio controlador de eventos.As an alternative to OnExited, you can write your own event handler. Cree su propio delegado de controlador de eventos y su propio método de control de eventos.You create your own event handler delegate and your own event-handling method.

Nota

Si usa el entorno de Visual Studio, se creará automáticamente un delegado de controlador de eventos (AddOnExited) y un método de control de eventos (Process1_Exited) al arrastrar un Process componente a un formulario y hacer doble clic en el icono.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. El código que se crea para ejecutarse cuando se Exited produce el evento se escribe en el procedimiento Process1_Exited.The code you create to run when the Exited event occurs is entered into the Process1_Exited procedure. No es necesario crear el OnExited miembro, ya que se implementa automáticamente.You do not need to create the OnExited member, because it is implemented for you.

Cuando se genera un evento, se invoca el controlador de eventos a través de un delegado.Raising an event invokes the event handler through a delegate. Para obtener información general, consulte controlar y provocar eventos.For an overview, see Handling and Raising Events.

Se aplica a

Consulte también