Process.SynchronizingObject Właściwość

Definicja

Pobiera lub ustawia obiekt używany do marshalingu wywołań procedury obsługi zdarzeń, które są wystawiane w wyniku zdarzenia zakończenia procesu.

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

Wartość właściwości

Używany ISynchronizeInvoke do marshalingu wywołań procedury obsługi zdarzeń, które są wystawiane w wyniku Exited zdarzenia w procesie.

Atrybuty

Przykłady

   ref class MyButton: public Button
   {
   public:
      void MyProcessExited( Object^ source, EventArgs^ e )
      {
         MessageBox::Show( "The process has exited." );
      }
   };

public:
   MyButton^ button1;
private:
   void MyProcessExited( Object^ source, EventArgs^ e )
   {
       MessageBox::Show( "The process has exited." );
   }
   void button1_Click( Object^ sender, EventArgs^ e )
   {
      Process^ myProcess = gcnew Process;
      ProcessStartInfo^ myProcessStartInfo = gcnew ProcessStartInfo( "mspaint" );
      myProcess->StartInfo = myProcessStartInfo;
      myProcess->Start();
      myProcess->Exited += gcnew System::EventHandler( this, &Form1::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();
      myProcess->Close();
   }
    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

Uwagi

W SynchronizingObject przypadku nullmetody , które obsługują Exited zdarzenie, są wywoływane w wątku z puli wątków systemowych. Aby uzyskać więcej informacji na temat pul wątków systemowych, zobacz ThreadPool.

Exited Gdy zdarzenie jest obsługiwane przez składnik Windows Forms wizualizacji, taki jak Button, uzyskiwanie dostępu do składnika za pośrednictwem puli wątków systemowych może nie działać lub może spowodować wyjątek. Należy tego uniknąć, ustawiając SynchronizingObject składnik Windows Forms, co powoduje wywołanie metod obsługi Exited zdarzenia w tym samym wątku, w którym został utworzony składnik.

Jeśli element Process jest używany w programie Visual Studio 2005 w projektancie Windows Forms, SynchronizingObject zostanie automatycznie ustawiony na kontrolkę zawierającą Processelement . Jeśli na przykład umieścisz element Process w projektancie ( Form1 który dziedziczy z Formklasy ) SynchronizingObject właściwość Process jest ustawiona na wystąpienie klasy Form1:

this->process1->StartInfo->Domain = "";
this->process1->StartInfo->LoadUserProfile = false;
this->process1->StartInfo->Password = nullptr;
this->process1->StartInfo->StandardErrorEncoding = nullptr;
this->process1->StartInfo->StandardOutputEncoding = nullptr;
this->process1->StartInfo->UserName = "";
this->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

Zazwyczaj ta właściwość jest ustawiana, gdy składnik jest umieszczany wewnątrz kontrolki lub formularza, ponieważ te składniki są powiązane z określonym wątkiem.

Dotyczy

Zobacz też