다음을 통해 공유


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

속성 값

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

특성

예제

    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

설명

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

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

Windows Forms 디자이너 SynchronizingObject 에서 Process Visual Studio 2005 내에서 사용되는 경우 해당 컨트롤이 포함된 컨트롤로 자동으로 설정됩니다Process. 예를 들어 디자이너에서 상속 SynchronizingObjectForm되는 디자이너에 Form1 배치 Process 하는 경우 해당 Process 속성은 다음의 인스턴스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

이러한 구성 요소는 특정 스레드에 바인딩되므로 일반적으로 이 속성은 구성 요소가 컨트롤 또는 폼 내에 배치되는 경우 설정됩니다.

적용 대상

추가 정보