ApplicationDeployment.CheckForUpdate Method

Definition

Checks UpdateLocation to determine whether a new update is available.

Overloads

CheckForUpdate()

Checks UpdateLocation to determine whether a new update is available.

CheckForUpdate(Boolean)

Checks UpdateLocation to determine whether a new update is available.

CheckForUpdate()

Checks UpdateLocation to determine whether a new update is available.

C#
public bool CheckForUpdate();

Returns

true if a new update is available; otherwise, false.

Exceptions

ClickOnce throws this exception immediately if you call the CheckForUpdate() method while an update is already in progress.

The deployment manifest cannot be downloaded.

The deployment manifest is corrupted. You will likely need to redeploy the application to fix this problem.

Examples

The following code example checks for an application update; if one is available, it installs it synchronously.

C#
private void InstallUpdateSync()
{
    if (ApplicationDeployment.IsNetworkDeployed)
    {
        Boolean updateAvailable = false;
        ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;

        try
        {
            updateAvailable = ad.CheckForUpdate();
        }
        catch (DeploymentDownloadException dde)
        {
            // This exception occurs if a network error or disk error occurs
            // when downloading the deployment.
            MessageBox.Show("The application cannt check for the existence of a new version at this time. \n\nPlease check your network connection, or try again later. Error: " + dde);
            return;
        }
        catch (InvalidDeploymentException ide)
        {
            MessageBox.Show("The application cannot check for an update. The ClickOnce deployment is corrupt. Please redeploy the application and try again. Error: " + ide.Message);
            return;
        }
        catch (InvalidOperationException ioe)
        {
            MessageBox.Show("This application cannot check for an update. This most often happens if the application is already in the process of updating. Error: " + ioe.Message);
            return;
        }

        if (updateAvailable)
        {
            try
            {
                ad.Update();
                MessageBox.Show("The application has been upgraded, and will now restart.");
                Application.Restart();
            }
            catch (DeploymentDownloadException dde)
            {
                MessageBox.Show("Cannot install the latest version of the application. Either the deployment server is unavailable, or your network connection is down. \n\nPlease check your network connection, or try again later. Error: " + dde.Message);
            }
            catch (TrustNotGrantedException tnge)
            {
                MessageBox.Show("The application cannot be updated. The system did not grant the application the appropriate level of trust. Please contact your system administrator or help desk for further troubleshooting. Error: " + tnge.Message);
            }
        }
    }
}

Remarks

The CheckForUpdate method compares the version of the currently installed deployment with the version specified in the deployment manifest found at UpdateLocation. If the version on the server is different from the installed version, it returns true.

This method will block until the check has completed. To check for an update asynchronously, use the CheckForUpdateAsync method instead.

Note

If CheckForUpdate discovers that an update is available, and the user chooses not to install it, ClickOnce will prompt the user that an update is available the next time the application is run. There is no way to disable this prompting. (If the application is a required update, ClickOnce will install it without prompting.)

See also

Applies to

.NET Framework 4.8.1 et autres versions
Produit Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

CheckForUpdate(Boolean)

Checks UpdateLocation to determine whether a new update is available.

C#
public bool CheckForUpdate(bool persistUpdateCheckResult);

Parameters

persistUpdateCheckResult
Boolean

If false, the update will be applied silently and no dialog box will be displayed.

Returns

true if a new update is available; otherwise, false.

Applies to

.NET Framework 4.8.1 et autres versions
Produit Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1