The normal procedure is like this:
- The main program detects that an update is ready.
- The main program silently downloads the update to a temporary location. The download is performed in a background thread.
- When the download is complete and verified, the main program restarts.
- Whenever the program starts and notices that there is a new update waiting to be installed it terminates and runs a separate executable that performs the update.
- When the update is complete, the program is restarted again.
The main benefit of this is that the user is not compelled to wait for the download to occur. A process which may take time and may fail. Thus giving the user as little downtime as possible.
There is a tricky scenario to handle. That's when the program starts the updater and then shuts itself down. If the main process doesn't close before the update opens the executable, then the updater can fail. The most elegant way to handle this is for the main program to pass its PID to the updater. The updater can then open a handle to that process and wait until it is signaled.
An alternative approach, quite similar, goes like this:
- The main program detects that an update is ready and fires off a separate executable to perform the update. Or, the main program periodically fires off the updater to check whether or not there is an update available.
- The update process silently downloads the update to a temporary location.
- When the download is complete and verified, the updater signals the main process to terminate.
- Once the main process has terminated (the updater waits for it to do so), the updater performs the update.
- When the update is complete, the main program is restarted.
To be honest, the second approach seems more attractive to me. It has a much better separation of concerns. The main program is concerned with its business. The updater is concerned with its job. Obviously there has to be interaction and cooperation between them, but this is kept to a bare minimum.