Process.SynchronizingObject プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > Process.SynchronizingObject プロパティの意味・解説 

Process.SynchronizingObject プロパティ

プロセス終了イベントの結果として発行されるイベント ハンドラ呼び出しをマーシャリングするために使用するオブジェクトを取得または設定します。

名前空間: System.Diagnostics
アセンブリ: System (system.dll 内)
構文構文

Public Property SynchronizingObject As
 ISynchronizeInvoke
Dim instance As Process
Dim value As ISynchronizeInvoke

value = instance.SynchronizingObject

instance.SynchronizingObject = value
public ISynchronizeInvoke SynchronizingObject { get;
 set; }
public:
property ISynchronizeInvoke^ SynchronizingObject {
    ISynchronizeInvoke^ get ();
    void set (ISynchronizeInvoke^ value);
}
/** @property */
public ISynchronizeInvoke get_SynchronizingObject ()

/** @property */
public void set_SynchronizingObject (ISynchronizeInvoke
 value)
public function get SynchronizingObject
 () : ISynchronizeInvoke

public function set SynchronizingObject
 (value : ISynchronizeInvoke)

プロパティ値
プロセスの Exited イベントの結果として発行されるイベント ハンドラ呼び出しをマーシャリングするために使用する ISynchronizeInvoke。

解説解説

SynchronizingObject が null 参照 (Visual Basic では Nothing) の場合、Exited イベントを処理するメソッドはシステムのスレッド プールのスレッドで呼び出されます。システム スレッド プールの詳細については、ThreadPool のトピックを参照してください。

Exited イベントを Button などのビジュアルな Windows フォーム コンポーネントで処理するとき、システム スレッド プールを通じてコンポーネントにアクセスすると、適切に動作しなかったり、例外が発生する場合があります。これを防ぐには、SynchronizingObject に Windows フォームのコンポーネントを設定して、コンポーネントが作成されているスレッドと同じスレッドで Exited イベントを処理するメソッドが呼び出されるようにします。

Visual Studio 2005 内部の Windows フォーム デザイナで Process を使用すると、SynchronizingObject には Process が格納されているコントロールが自動的に設定されます。たとえば、Form から継承される Form1 のデザイナに Process を配置した場合、Process の SynchronizingObject プロパティには Form1 のインスタンスが設定されます。

通常、コンポーネントがコントロールまたはフォームの中にあると、これらのコンポーネントは特定のスレッドにバインドされるため、このプロパティが設定されます。

使用例使用例
   Private button1 As MyButton
   Private Sub button1_Click(sender As
 Object, e As EventArgs)
      Dim 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()
      myProcess.Close()
   End Sub 'button1_Click
   Private Sub MyProcessExited(source As
 Object, e As EventArgs)
      MessageBox.Show("The process has exited.")
   End Sub 'MyProcessExited
End Class 'Form1

Public Class MyButton
   Inherits Button

End Class 'MyButton
   private MyButton button1;
   private void button1_Click(object sender,
 System.EventArgs e)
   {
      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();
      myProcess.Close();
   }
   private void MyProcessExited(Object source,
 EventArgs e)
   {
      MessageBox.Show("The process has exited.");
   }
}

public class MyButton:Button
{

}
   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)
    {
        System.Diagnostics.Process myProcess = 
            new System.Diagnostics.Process();
        ProcessStartInfo myProcessStartInfo = 
            new ProcessStartInfo("mspaint");
        myProcess.set_StartInfo(myProcessStartInfo);
        myProcess.Start();
        myProcess.add_Exited(new EventHandler(MyProcessExited));
        // Set 'EnableRaisingEvents' to true, to raise 'Exited' event
 when
        // process is terminated.
        myProcess.set_EnableRaisingEvents(true);

        // Set method handling the exited event to be called;
        // on the same thread on which MyButton was created.
        myProcess.set_SynchronizingObject(button1);
        MessageBox.Show("Waiting for the process 'mspaint'
 to exit....");
        myProcess.WaitForExit();
        myProcess.Close();
    } //button1_Click
    private void MyProcessExited(Object source,
 EventArgs e)
    {
        MessageBox.Show("The process has exited.");
    } //MyProcessExited
} //Form1

public class MyButton extends Button
{
.NET Framework のセキュリティ.NET Framework のセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

Process.SynchronizingObject プロパティのお隣キーワード

   

英語⇒日本語
日本語⇒英語
   



Process.SynchronizingObject プロパティのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS