Consider the following scenario: I'm running my application which, during its execution, has to run another process and only after that 2nd process finishes inner specific initialization, can my first process continue. E.g:
...
// Process1 code does various initializations here
Process.Start("Process2.exe");
// Wait until Process2 finishes its initialization and only then continue (Process2 doesn't exit)
...
I see several options:
- Mutex - Mutex comes to mind automatically when considering interprocess communication, however, I can't see a way of causing Process1 to wait for a mutex that he generated himself. I can cause Process2 to create a mutex and wait on Process1 till the Mutex is created (using polling and Mutex.OpenExisting function)
- AutoResetEvent - Those would be perfect for the task, however, in seems that under .NET these can't be used for interprocess communcation.
- CreateEvent - I can use P/Invoke and use Win32 CreateEvent function. In theory, it could provide me with everything I need. I'd rather not using native functions, however, if possible.
- Use external file - The easiest way would be just to use some OS external object (file, registry, etc). However, this seems rather hacky, however.
I'd be happy to hear your opinion for this case.
Thanks!