My preferred solution that Peter Lang is associated with is to use Sockets. When the application starts, you can start the server socket, which will listen for incoming connections on localhost (plus the port of your choice). Before this happens in your code, although you can try and establish a connection to the server socket, and if it succeeds, you know that another instance is already open, so you can exit the current instance with the corresponding message.
In the implementation of your server socket, you can also add functionality that, when receiving an incoming connection, will actually make the current application instance go to the forefront.
Davejohnston
source share