Multiple simultaneous .NET IPC servers / find the right one by process ID?
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 somew开发者_如何转开发here, 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?
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.
精彩评论