多个同步 .NET IPC 服务器/通过进程 ID 找到正确的服务器?

发布于 2024-09-11 09:20:44 字数 440 浏览 4 评论 0原文

我有一个数据库客户端应用程序。有些人会运行它的多个实例(即进程)来同时连接到不同的数据库。我想让这个应用程序接受简单命令的自定义 URI 方案,例如“打开记录 123”。 URI 包含它所属的数据库,因此,根据 URL 的内容,一个特定进程“有资格”处理它。

因此,我决定创建一个用于 URI 处理的附加应用程序,该应用程序 1) 不会持续运行,但仅在单击某个 URI 时通过 Windows 调用,2) 找到正确的客户端并将 URL 传递给它。我在数据库客户端上使用了 IpcServerChannel ,并在 URI 处理程序中使用了 IpcClientChannel ,以便 URI 处理程序可以询问客户端它负责哪个数据库。

但是,我该如何为多个客户处理这个问题呢? URI 处理程序如何“发现”哪些客户端(即 IPC 服务器)当前正在运行,以及如何通过 IPC 连接到它们?

I have a database client application. Some people will run multiple instances (i.e. processes) of it to connect to different databases simultaneously. I'd like to have this app accept a custom URI scheme for simple commands such as 'open record 123'. The URI contains the database it pertains to, so, depend on the contents of the URL, one particular process is 'eligible' to handle it.

As such, I've decided to create an additional app for URI handling that 1) isn't constantly running, but only invoked through Windows when a URI is clicked somewhere, and 2) finds the right client and passes the URL on to it. I've used an IpcServerChannel on the database client, and an IpcClientChannel in the URI handler, so that the URI handler can ask the client which database it's responsible for.

How do I handle this for multiple clients, though? How can the URI handler 'discover' which clients (i.e. IPC servers) are currently running, and how to connect to them through IPC?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笔落惊风雨 2024-09-18 09:20:44

每个客户端应用程序在启动时注册的 Windows 服务将是处理这种情况的相当合理的方式,因为它还可以处理 URI 处理。

不过,您可能需要考虑以下几件事:

  • 该服务将如何处理登录到一台 PC 的多个用户
  • 该服务将如何处理强制终止或崩溃的客户端应用程序实例

回应您关于不希望URI 处理程序不断运行:

如果您有客户端应用程序/URI 处理程序(可能与 .msi 安装触发 Windows Installer 服务启动的方式类似)启动该服务(如果当前未运行),并让该服务自行终止当它不再有任何正在运行的客户端时,您将满足该要求。

A windows service that each client app registers with when it starts up would be a fairly reasonable way of handling this scenario as it could also take care of URI processing.

A couple of things you may want to think about though:

  • How will the service handle multiple users being logged into a single PC
  • How will the service handle instances of the client app that are force terminated or crash

To respond to your comment about not wanting the URI handler constantly running:

If you have the client application / URI Handler (in a similar way to the way .msi installation triggers the Windows Installer service to start, perhaps) start the service if it's not currently running, and have the service terminate itself when it no longer has any running clients you'll achieve that requirement.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文