Which is the preferred way to communicate between a shell extension and an application both written in C#

StackOverflow https://stackoverflow.com/questions/16056202

  •  04-04-2022
  •  | 
  •  

Question

i've written a shell extension in C# which shows my own context menu entry (FileExtensionMenu) After clicking my menu entry the shell extension should submit the choosen file name to my main application that it can process with this file.

My question is which is the way to communicate between the extension and the application. Or must i transfer the program logic to the shell extension code?

Thanks in advance for your help

Was it helpful?

Solution

You can use Windows Communication Foundation (WCF) to call methods in your running application. It's somewhat fiddly to set up, but once you have it makes it very easy to call methods via RPC.

Note that the methods are called from a separate thread, so you'd need to marshal it to the UI calls if necessary (using Control.Invoke() or Control.BeginInvoke() for Windows Forms).

See here for full details.

Also, see here for a simple example. As Adam says below, you will need to use named pipes as the transport mechanism, so when looking at that example bear in mind that instead of

new NetTcpBinding(),
"net.tcp://localhost:8000");

you will have something like:

new NetNamedPipeBinding(),
"net.pipe://localhost/YourServiceNameGoesHere"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top