0

I have a C# Winforms application which I need to invoke on certain system events;

  • the user clicks a link with a custom protocol of mylink:
  • the user opens a file with an extension of .mylink

The registry settings are done, and the app launches properly on these events. However I do not want multiple instances of the app instantiated. If the app is already running, it should receive a notification from Windows that a new file/protocol event has occurred that it should process.

In the past this was done with DDE. The app would be setup as a DDE server, and Windows explorer would send a DDE message. But that was... 20 years ago. Is there a replacement process for these shell-to-application invoke events?

I've been digging through SO and MS docs and have had no luck finding guidance on this. Pipes have largely replaced DDE, but I haven't found a mechanism that defines pipe communication between Explorer and a registered protocol handler / filetype handler.

If I'm forced to I could create a bootstrap handler app that launches on every invocation event and then launches or establishes a pipe to my main app... this process seems obtuse though, and was not needed with DDE. I'm hoping there's a better way?

Memetican
  • 381
  • 5
  • 18
  • 1
    Maybe helpful: https://stackoverflow.com/questions/19147/what-is-the-correct-way-to-create-a-single-instance-wpf-application but I do expect you do need a pipe or some other means to hand over arguments from a new instance to the already running instance AFAIK. – rene Sep 18 '22 at 11:23
  • 1
    See following : https://www.elevenforum.com/t/start-stop-and-restart-services-in-windows-11.3088/ – jdweng Sep 18 '22 at 11:25
  • Yes I'm exploring a combined approach at the moment. Not a service, but rather a Mutex-based pattern. The OS would always invoke the same exe, but if it's already running (as determined by Mutex) it will try to establish a pipe connection to the running instance and pass it the command request. A lot of code for such a simple thing. Seems like a common app pattern. We'll see if my approach works, but I'm hoping someone knows a better option. – Memetican Sep 18 '22 at 12:03
  • Maybe look at the visualbasic Application model: https://learn.microsoft.com/en-us/dotnet/visual-basic/developing-apps/development-with-my/overview-of-the-visual-basic-application-model as it does have out of the box handling of single and next instance events with passing arguments around. – rene Sep 18 '22 at 12:44

0 Answers0