Process.SynchronizingObject プロパティ

定義

プロセス終了イベントの結果として発行されるイベント ハンドラー呼び出しをマーシャリングするために使用するオブジェクトを取得または設定します。Gets or sets the object used to marshal the event handler calls that are issued as a result of a process exit event.

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

プロパティ値

プロセスの Exited イベントの結果として発行されるイベント ハンドラー呼び出しをマーシャリングするために使用する ISynchronizeInvokeThe ISynchronizeInvoke used to marshal event handler calls that are issued as a result of an Exited event on the process.

属性

   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

注釈

SynchronizingObjectnull場合、Exited イベントを処理するメソッドは、システムスレッドプールからのスレッドで呼び出されます。When SynchronizingObject is null, methods that handle the Exited event are called on a thread from the system thread pool. システムスレッドプールの詳細については、「ThreadPool」を参照してください。For more information about system thread pools, see ThreadPool.

Exited イベントが、Buttonなどのビジュアル Windows フォームコンポーネントによって処理されると、システムスレッドプールを介してコンポーネントにアクセスできない場合や、例外が発生する場合があります。When the Exited event is handled by a visual Windows Forms component, such as a Button, accessing the component through the system thread pool might not work, or might result in an exception. これを回避するには、SynchronizingObject を Windows フォームコンポーネントに設定します。これにより、Exited イベントを処理するメソッドが、コンポーネントが作成されたのと同じスレッドで呼び出されます。Avoid this by setting SynchronizingObject to a Windows Forms component, which causes the methods handling the Exited event to be called on the same thread on which the component was created.

Process が Windows フォームデザイナーの Visual Studio 2005Visual Studio 2005 内で使用されている場合、SynchronizingObject は、Processを含むコントロールに自動的に設定されます。If the Process is used inside Visual Studio 2005Visual Studio 2005 in a Windows Forms designer, SynchronizingObject is automatically set to the control that contains the Process. たとえば、Form1 (Formから継承) のデザイナーに Process を配置すると、ProcessSynchronizingObject プロパティが Form1のインスタンスに設定されます。For example, if you place a Process on a designer for Form1 (which inherits from Form) the SynchronizingObject property of Process is set to the instance of 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

通常、このプロパティは、コンポーネントがコントロールまたはフォーム内に配置されるときに設定されます。これは、コンポーネントが特定のスレッドにバインドされるためです。Typically, this property is set when the component is placed inside a control or form, because those components are bound to a specific thread.

セキュリティ

LinkDemand
直前の呼び出し元に対する完全な信頼の場合。for full trust for the immediate caller. このメンバーは、部分的に信頼されているコードから使用することはできません。This member cannot be used by partially trusted code.

適用対象

こちらもご覧ください