Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Signalling to a parent process that a child process is fully initialised

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!!
like image 634
chillitom Avatar asked Nov 15 '10 17:11

chillitom


1 Answers

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.

like image 84
Jeff Yates Avatar answered Sep 29 '22 11:09

Jeff Yates