Search code examples
c#single-instance

Passing string between 2 C# application instances


I built a media player, that media player is associated with several media file types.
Every time that a user opens a media file, I check if my player is open.
I managed to prevent opening two instances but I want to pass the file path to the already opened instance.

I am using mutex to prevent opening and I have been trying to use SendMessage to pass strings.
What is the best way to do so?


Solution

  • Try named pipes, i.e.NamedPipeServerStream & NamedPipeClientStream. Some general overview is avaibale here as well, although in your case basic write-to-temp-lock-file/read-from-temp-lock-file might not be such a bad idea.