I'm launching a child process that exposes a WCF endpoint. How can I signal from the child process to the parent process that the child is fully initialised and that it can now access the endpoint?
I'd thought about using Semaphores for this purpose but can't quite figure out how to achieve the required signal.
string pipeUri = "net.pipe://localhost/Node0";
ProcessStartInfo startInfo = new ProcessStartInfo("Node.exe", "-uri=" + pipeUri);
Process p = Process.Start(startInfo);
NetNamedPipeBinding binding = new NetNamedPipeBinding();
var channelFactory = new ChannelFactory<INodeController>(binding);
INodeController controller = channelFactory.CreateChannel(new EndpointAddress(pipeUri));
// need some form of signal here to avoid..
controller.Ping() // EndpointNotFoundException!!
I would use a system-wide EventWaitHandle
for this. The parent application can then wait for the child process to signal that event.
Both processes create the named event and then one waits for it to be signalled.
// I'd probably use a GUID for the system-wide name to
// ensure uniqueness. Just make sure both the parent
// and child process know the GUID.
var handle = new EventWaitHandle(
false,
EventResetMode.AutoReset,
"MySystemWideUniqueName");
While the child process will just signal the event by calling handle.Set()
, the parent process waits for it to be set using one of the WaitOne
methods.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With