Process.SynchronizingObject プロパティ
アセンブリ: System (system.dll 内)

Dim instance As Process Dim value As ISynchronizeInvoke value = instance.SynchronizingObject instance.SynchronizingObject = value
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 {


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からProcess.SynchronizingObject プロパティを検索する場合は、下記のリンクをクリックしてください。

- Process.SynchronizingObject プロパティのページへのリンク