信令到父进程,子进程完全初始化 [英] Signalling to a parent process that a child process is fully initialised

查看:125
本文介绍了信令到父进程,子进程完全初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发起了公开一个WCF终结子进程。如何从子进程的父进程的孩子完全初始化信号,它现在可以访问端点?

我倒是想过用信号量用于此目的,但不能完全弄清楚如何实现所需的信号。

 字符串pipeUri =net.pipe://本地主机/ NODE0;
        的ProcessStartInfo的StartInfo =新的ProcessStartInfo(Node.exe,-uri =+ pipeUri);
        进程p =的Process.Start(StartInfo的);
        NetNamedPipeBinding绑定=新NetNamedPipeBinding();
        VAR的ChannelFactory =新的ChannelFactory< INodeController>(绑定);
        INodeController控制器= channelFactory.CreateChannel(新的EndpointAddress(pipeUri));

        //需要某种形式的信号,在这里,以避免..
        controller.Ping()// EndpointNotFoundException!
 

解决方案

我会用一个全系统的 的EventWaitHandle 这一点。然后,父应用程序可以等待子进程发出信号的事件。

这两个过程都创建命名事件,然后有等待其发出信号。

  //我可能会使用一个GUID的系统范围名
//确保其唯一性。只要确保这两个父
//和子进程知道GUID。
VAR手柄=新的EventWaitHandle(
    假,
    EventResetMode.AutoReset,
    MySystemWideUniqueName);
 

虽然子进程将只通过调用信号事件 handle.Set(),父进程等待它被使用<$ C $的一个集C> WaitOne的的方法。

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.

这篇关于信令到父进程,子进程完全初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆