Welcome to MSDN Blogs Sign in | Join | Help

Process Creation and Coordination

In some previous posts (Out of Process IPC/TCP Remoting code, .Net Remoting (AppDomains, Out of Process, Two Way, etc..)) I showed some sample code using .Net remoting over a process boundary. As a result, I received a few questions about the process creation and how to handle the process coordination (i.e., The Host/Master process waiting on the created process startup). I apologize to those who have been waiting for another sample on the subject, but I have been pretty busy as of late.

The attached sample code shows the following;

1.     How to ensure the Host Process waits on the new process creation.

a.     Previously I showed a simple *hack* where the created process sleeps for a while in order to let the process creation complete.

b.     A much cleaner and more reliable solution uses EventWaitHandle.

2.     The created Process runs until the Host Process is terminated or the Host terminates the new process.

a.     Previously I showed a simple *hack* where the created process does a Console.ReadLine() in order to halt code execution and thus cause process termination.

b.     I didn’t show an example of how the created process can shutdown in the event the Host process shuts down. This scenario covers orphaned processes.

c.     The solution: System.Diagnostics.Process.GetProcessById(HostPID).WaitForExit();

View Source for Host Process: Show Code ...

View Source for Created Process: Show Code ...

Published Monday, August 11, 2008 4:27 PM by JackG
Filed under: ,

Attachment(s): WaitForProcessStartup.zip

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Jack Gudenkauf JackG WebLog Process Creation and Coordination | Paid Surveys

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker