Compartir por


Process.SynchronizingObject Propiedad

Definición

Obtiene o establece el objeto utilizado para serializar las llamadas del controlador de eventos que se emiten como resultado de un evento de salida de proceso.

public:
 property System::ComponentModel::ISynchronizeInvoke ^ SynchronizingObject { System::ComponentModel::ISynchronizeInvoke ^ get(); void set(System::ComponentModel::ISynchronizeInvoke ^ value); };
public System.ComponentModel.ISynchronizeInvoke? SynchronizingObject { get; set; }
public System.ComponentModel.ISynchronizeInvoke SynchronizingObject { get; set; }
[System.ComponentModel.Browsable(false)]
public System.ComponentModel.ISynchronizeInvoke SynchronizingObject { get; set; }
member this.SynchronizingObject : System.ComponentModel.ISynchronizeInvoke with get, set
[<System.ComponentModel.Browsable(false)>]
member this.SynchronizingObject : System.ComponentModel.ISynchronizeInvoke with get, set
Public Property SynchronizingObject As ISynchronizeInvoke

Valor de propiedad

que ISynchronizeInvoke se usa para serializar las llamadas al controlador de eventos que se emiten como resultado de un Exited evento en el proceso.

Atributos

Ejemplos

    private MyButton button1;
    private void button1_Click(object sender, System.EventArgs e)
    {
        using (Process myProcess = new Process())
        {
            ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("mspaint");
            myProcess.StartInfo = myProcessStartInfo;
            myProcess.Start();
            myProcess.Exited += new EventHandler(MyProcessExited);
            // Set 'EnableRaisingEvents' to true, to raise 'Exited' event when process is terminated.
            myProcess.EnableRaisingEvents = true;
            // Set method handling the exited event to be called  ;
            // on the same thread on which MyButton was created.
            myProcess.SynchronizingObject = button1;
            MessageBox.Show("Waiting for the process 'mspaint' to exit....");
            myProcess.WaitForExit();
        }
    }
    private void MyProcessExited(Object source, EventArgs e)
    {
        MessageBox.Show("The process has exited.");
    }
}

public class MyButton : Button
{
}
    Private button1 As MyButton
    Private Sub button1_Click(sender As Object, e As EventArgs)
        Using myProcess As New Process()
            Dim myProcessStartInfo As New ProcessStartInfo("mspaint")
            myProcess.StartInfo = myProcessStartInfo
            myProcess.Start()
            AddHandler myProcess.Exited, AddressOf MyProcessExited
            ' Set 'EnableRaisingEvents' to true, to raise 'Exited' event when process is terminated.
            myProcess.EnableRaisingEvents = True
            ' Set method handling the exited event to be called  ;
            ' on the same thread on which MyButton was created.
            myProcess.SynchronizingObject = button1
            MessageBox.Show("Waiting for the process 'mspaint' to exit....")
            myProcess.WaitForExit()
        End Using
    End Sub

    Private Sub MyProcessExited(source As Object, e As EventArgs)
        MessageBox.Show("The process has exited.")
    End Sub
End Class

Public Class MyButton
    Inherits Button

End Class

Comentarios

Cuando SynchronizingObject es null, se llama a los métodos que controlan el Exited evento en un subproceso desde el grupo de subprocesos del sistema. Para obtener más información sobre los grupos de subprocesos del sistema, consulte ThreadPool.

Cuando un componente visual de Windows Forms controla el Exited evento, como , Buttonel acceso al componente a través del grupo de subprocesos del sistema podría no funcionar o podría dar lugar a una excepción. Evite esto estableciendo SynchronizingObject en un componente de Windows Forms, lo que hace que se llame a los métodos que controlan el Exited evento en el mismo subproceso en el que se creó el componente.

Process Si se usa en Visual Studio 2005 en un diseñador de Windows Forms, SynchronizingObject se establece automáticamente en el control que contiene .Process Por ejemplo, si coloca un Process en un diseñador para Form1 (que hereda de Form) la SynchronizingObject propiedad de Process se establece en la instancia de Form1:

process1.StartInfo.Domain = "";
process1.StartInfo.LoadUserProfile = false;
process1.StartInfo.Password = null;
process1.StartInfo.StandardErrorEncoding = null;
process1.StartInfo.StandardOutputEncoding = null;
process1.StartInfo.UserName = "";
process1.SynchronizingObject = this;
process1.StartInfo.Domain <- "";
process1.StartInfo.LoadUserProfile <- false;
process1.StartInfo.Password <- null;
process1.StartInfo.StandardErrorEncoding <- null;
process1.StartInfo.StandardOutputEncoding <- null;
process1.StartInfo.UserName <- "";
process1.SynchronizingObject <- this;
process1.StartInfo.Domain = ""
process1.StartInfo.LoadUserProfile = False
process1.StartInfo.Password = Nothing
process1.StartInfo.StandardErrorEncoding = Nothing
process1.StartInfo.StandardOutputEncoding = Nothing
process1.StartInfo.UserName = ""
process1.SynchronizingObject = Me

Normalmente, esta propiedad se establece cuando el componente se coloca dentro de un control o formulario, ya que esos componentes están enlazados a un subproceso específico.

Se aplica a

Consulte también