Reputation: 4581
I have a C# Windows Forms application that is manually started and then mostly runs in the background. In my registry, this program is set up to handle a "dstel" url protocol. That is, href="dstel:1234567890"
will successfully open my program.
The issue is that my program needs have only one instance running at any given time. My research suggests that in order to ensure that multiple instances are not operating simultaneously, I should use a mutex (courtesy of How to check if another instance of the application is running).
Assuming that works, I am now left with what to do when someone clicks on my special dstel link in a webpage. What I need is how can I redirect the command line input to method xyz() of my already-running application?
To be clear, I'm envisioning the following events, in order:
I have a few things in mind that might work, most notably either using a helper application or setting up a named pipe via WCF. I am open to any suggestions you may have.
Thanks!
Upvotes: 1
Views: 922
Reputation: 1712
If you override this class for your base app and set its protected IsSingleInstance
property as true, you can override the method OnStartupNextInstance()
, which gets called anytime a subsequent instance of your program is started.
This should do it like you want!
Upvotes: 1