一方のアプリケーションがタスクを完了したことを他方のアプリケーションに通知するだけでよい場合は、名前付きの EventWaitHandle を使用するのが最も簡単な方法です。オブジェクトは非シグナル状態で作成されます。最初のアプリはハンドルを待機し、2 番目のアプリはジョブの完了時にハンドルを通知します。例えば:
// First application
EventWaitHandle waitForSignal = new EventWaitHandle(false, EventResetMode.ManualReset, "MyWaitHandle");
// Here, the first application does whatever initialization it can.
// Then it waits for the handle to be signaled:
// The program will block until somebody signals the handle.
waitForSignal.WaitOne();
これにより、最初のプログラムが同期を待機するように設定されます。2 番目のアプリケーションも同様に単純です。
// Second app
EventWaitHandle doneWithInit = new EventWaitHandle(false, EventResetMode.ManualReset, "MyWaitHandle");
// Here, the second application initializes what it needs to.
// When it's done, it signals the wait handle:
doneWithInit.Set();
2 番目のアプリケーションが Set を呼び出すと、イベントが通知され、最初のアプリケーションが続行されます。