I released the last beta of SoundSwitch adding a simple but useful feature: IPC.

Before I started maintaining SoundSwitch, it was using a Mutex to check if it’s already launched, and in that case, would abort the launch. It’s a simple mechanism to avoid having 2 instances of the program in the same time.

I received a particular request to make a new instance of SoundSwitch close the previous one and take the control. I searched a little how to do this easily without overburdening the application since I want to keep it lightweight.

On a previous university project (Organ Defence) I had to implement a handler of Pipes, since we had the game engine as the main process and a child spawned for each player joining the game. The child was managing all the network part and using the pipe relaying the information to the game engine.

I thought why not reuse the same principle, using a named pipe between the 2 instance of SoundSwitch.

Every time SoundSwitch is launched, it opens a named pipe waiting for a connection. This is done in another Thread to be sure it will not impede the normal workflow of the application. When SoundSwitch is launched and detects it’s already loaded (using the Mutex), it will connect to the pipe, authenticate itself Ā to the Pipe Server (the previously loaded instance of SoundSwitch) and ask the server to shut down the application gracefully.

In conclusion, it’s easy to implement especially with the basic tutorial on how to use Named Pipes provided by Microsoft. Furthermore, I created a basic system of command and authentification for the Pipe. Both the client and the server can communicate using this simplistic protocol. For now, I’m just using this to close the previous instance of SoundSwitch, but we can imagine it could be used for SoundSwitch to communicate with other processes in the future if the need arise.