Process.SynchronizingObject 속성

정의

프로세스 종료 이벤트의 결과로 발생하는 이벤트 처리기 호출을 마샬링하는 데 사용되는 개체를 가져오거나 설정합니다.

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

속성 값

프로세스에서 Exited 이벤트의 결과로 발생하는 이벤트 처리기 호출을 마샬링하는 데 사용되는 ISynchronizeInvoke입니다.

특성

예제

   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

설명

가 인 null경우 SynchronizingObject 이벤트를 처리하는 Exited 메서드는 시스템 스레드 풀의 스레드에서 호출됩니다. 시스템 스레드 풀에 대한 자세한 내용은 를 참조하세요 ThreadPool.

Exited 와 같은 Button시각적 Windows Forms 구성 요소에서 이벤트를 처리하는 경우 시스템 스레드 풀을 통해 구성 요소에 액세스하는 것이 작동하지 않거나 예외가 발생할 수 있습니다. 구성 요소를 만든 스레드에서 이벤트를 처리하는 Exited 메서드를 호출하는 Windows Forms 구성 요소로 설정 SynchronizingObject 하여 이 문제를 방지합니다.

Process 가 Windows Forms 디자이너 SynchronizingObject 의 Visual Studio 2005 내에서 사용되는 경우 는 가 포함된 컨트롤로 자동으로 설정됩니다Process. 예를 들어 에 대 Form1 한 디자이너에 배치 Process 하는 경우 (에서 Form상속) SynchronizingObjectProcess 속성은 의 instance 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

일반적으로 이 속성은 해당 구성 요소가 특정 스레드에 바인딩되기 때문에 구성 요소가 컨트롤 또는 폼 내에 배치되면 설정됩니다.

적용 대상

추가 정보