How to: Add On-Demand Programmatic Updates

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies.
This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
To create client business applications using current Microsoft technologies, see patterns & practices' Prism.

The automatic update options provided by ClickOnce work well for simple applications, but they do not provide explicit control over when application updates are downloaded and applied. As a result, users might have to wait for an indeterminate amount of time for their applications to launch if a large update is being downloaded or if the server is under high load.

If you want to explicitly control when updates are detected and downloaded, you can use the ClickOnce programmatic API to update your application after it starts. This kind of updating is often referred to as on-demand updates with ClickOnce. This topic describes how to add on-demand updates to the Bank Branch client application so that it checks for updates in the background after it starts.

On-demand updates can be combined with automatic updates if you want users to be able to check for updates whenever they want. This approach is logical only if you also select the automatic update option to check for updates after the application starts and to check for updates on a (relatively infrequent) scheduled basis.

Typically, if you are using on-demand updates, you use them as your only update mechanism so that your code can explicitly control when the updates occur. If you do this, you should consider checking for updates on a timer or on a background thread, downloading the updates when they are available, and then prompting the user when the update is ready to be applied. This approach minimizes the interruption for the user.

The ApplicationDeployment class exposes the on-demand API for performing ClickOnce programmatic updates. The class exposes both synchronous and asynchronous versions of the update API. The asynchronous methods use the asynchronous invocation pattern introduced in .NET Framework 2.0, which is based on synchronization contexts. These asynchronous methods ensure that their corresponding completed events are raised on the UI thread if the update is initiated from the UI thread. This removes the need for explicit marshaling of the event calls to the UI thread.

Note: If you are targeting a version of the .NET Framework that is earlier than 4.0 and you are using programmatic updates, your application will have to be uninstalled and reinstalled if you change signing certificates. For more information, including how to deal with this programmatically, see the MSDN article, Certificate Expiration in ClickOnce Deployment (

To apply on-demand updates, you have to:

  1. Add code to your application to check for and download updates whenever it is appropriate.
  2. Disable automatic updates when you publish the application.
  3. In the publishing properties, specify an update location URL that will be used by the ClickOnce API to perform update checking when you invoke it with the on-demand API.

For detailed information about adding on-demand updates to the Bank Branch Workbench application, see Adding an On-Demand Programmatic Update.

ClickOnce always applies the update the next time the application is launched after the update is downloaded through the on-demand API. If you want to delay applying the functionality contained in the update, you can use the Profile Catalog Service Web service to make sure that newly downloaded modules are not applied until some point in the future by not listing those modules in the profile catalog. For an example of how to do this, see How to: Apply Updates at a Future Time.