I need to have a single instance application (as per this answer), but it needs to be deployed via click once.
The problem is that I require that click once doesn’t automatically detect an update an attempt to load a newer version while the application is running. If it is running, then I need the other instance to be made active. Usually, when selecting a Click Once link, the very first thing it does is attempt to find an update. I want to intercept this and check for an already running instance prior to launching the normal update process.
Does anyone know how this is possible within a Click Once deployment scenario?
To tackle the problem, we built a prototype application which has the following two functionalities.
Multiple instances on one pc are disabled. A single instance application is deployed via clickonce. When a user tries to start a second instance of the app, a message will pop up indicating that ‘Another instance is already running’.
Checks for an update asynchronously, and installs the update if one exists. A message: ‘An update is available’ will pop up if there is an update available when a user runs a new instance.
The process to build the demo application is as follows:
Step 1: Detect an active instance application using Mutex class.
Step 2: Handle update programmatically
Before we do that, we should disable the automatic ClickOnce update checking (in the Publish — Updates… dialog).
Then we create two forms: UpdateProgress and mainForm, where UpdateProgress indicates download progress and mainForm represents the main application.
When a user runs the application, updateProgress will be launched firstly to check for updates. When updating completes, mainForm will start and updateProgress will be hidden.
The application works well and we hope it is a good solution for the problem.
Special thanks to Timothy Walters for providing the source code