C# 等待进程启动
我有 2 个程序(客户端和服务器)使用 ipc 进行通信。基本上,客户端在服务器上发送一些数据,并且它们在同一台计算机上工作。我希望客户端等待服务器进程启动(如果它尚未启动),但不太了解如何实现这一点。我考虑使用两个事件(一个是我的客户端创建的,一个是服务器创建的)并将两个调用包装在关键部分中等待这些事件。你会建议什么?
I have 2 programs(client and server) which communicates using ipc. Basically client sends some data at the server and they work at the same computer. I want the client to wait for server process to start if it does not already started but not quite understand how to achieve this. I think of using 2 events(one which is created my client and one created by server) and wrap both calls to waits for these events in critical section. What you will suggest?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
IPC如何工作?我假设是 NamedPipes,但这个想法对我来说是一样的。我过去必须做类似的事情,大致是这样的:
客户端启动,连接到IPC服务器(假设NamedPipes。应该无关紧要)
连接失败,客户端通过触发服务器启动来恢复(这可以通过多种方式处理,从从已知位置执行服务器二进制文件到使用触发启动服务)
服务器启动并作为第一件事声明IPC地址(或者全局互斥体,如果你更喜欢那个地址)。如果从多个客户端启动多个服务器进程,则第一个进程获胜,其他进程再次死亡。
客户端在适当的时间后重试
How does the IPC work? I assume NamedPipes, but the idea is the same for me. I had to do something like that in the past and did roughly this:
Client starts, connects to IPC server (assuming NamedPipes. Shouldn't matter)
Connection fails, client recovers by triggering a server start (this can be handled in lots of ways, from executing the server binary from a known location to using trigger started services)
Server starts and as one of the first thing claims the IPC address (or a global mutex if you like that one better). If multiple server processes are started from multiple clients, the first one wins and the others just die again.
Client retries after an appropriate time