How to: Add On-Demand Programmatic Update
This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies.
The automatic update options of ClickOnce work well for simple applications, but they do not provide explicit control of when application updates are downloaded and applied. As a result, users may have to wait for an indeterminate period 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 perform your application updating after your application 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 to check for updates in the background after the application launches.
On-demand updates can be combined with automatic updates if you want users to be able to check for updates whenever they want. This 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.
If you are using on-demand updates, you usually use them as your only update mechanism so your code can explicitly control when the updates occur. If you do this, you will usually want to check for updates on a timer or on a background thread, download the updates when they are available, and prompt the user when the update is ready to be applied to minimize 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 new asynchronous invocation pattern introduced in the .NET Framework 2.0 and later versions, 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.
To apply on-demand updates
- Add code to your application to check for and download updates whenever it is appropriate for your application.
- Disable automatic updates when you publish the application.
- Specify an update location URL in the publishing properties 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 BankBranchWorkbench application, see Manual: Add On-Demand Programmatic Update.
ClickOnce always applies the update the next time the application is launched after it is downloaded through the on-demand API. If you want to delay applying the functionality contained in the update, you can use the ProfileCatalogService Web service to ensure 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.