chi*_*tom 6 .net c# semaphore ipc process
我正在启动一个公开WCF端点的子进程.如何从子进程向父进程发出信号,表明子进程已完全初始化并且现在可以访问端点?
我想过为此目的使用信号量,但无法弄清楚如何实现所需的信号.
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!!
Run Code Online (Sandbox Code Playgroud)
EventWaitHandle我会为此使用系统范围的。然后,父应用程序可以等待子进程发出该事件的信号。
两个进程都会创建指定的事件,然后等待该事件发出信号。
// 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");
Run Code Online (Sandbox Code Playgroud)
虽然子进程仅通过调用来发出事件信号handle.Set(),但父进程等待使用其中一种WaitOne方法来设置该事件。
| 归档时间: |
|
| 查看次数: |
1438 次 |
| 最近记录: |