ApplicationDeployment::CheckForUpdate Method ()

 

Checks UpdateLocation to determine whether a new update is available.

Namespace:   System.Deployment.Application
Assembly:  System.Deployment (in System.Deployment.dll)

public:
bool CheckForUpdate()

Return Value

Type: System::Boolean

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

Exception Condition
InvalidOperationException

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

DeploymentDownloadException

The deployment manifest cannot be downloaded.

InvalidDeploymentException

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

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.

System_CAPS_noteNote

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.)

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

public:
    void LaunchUpdateWithTimeout()
    {
        if (ApplicationDeployment::IsNetworkDeployed)
        {
            ApplicationDeployment^ appDeployment =
                ApplicationDeployment::CurrentDeployment;
            appDeployment->UpdateCompleted +=
                gcnew AsyncCompletedEventHandler(this, 
                &Form1::deploy_UpdateCompleted);

            // The Interval property uses millisecond resolution.
            timer1->Interval = (1000 * 60) * 2;
            timer1->Start();

            appDeployment->UpdateAsync();
        }
    }

private:
    void deploy_UpdateCompleted(Object^ sender,
        AsyncCompletedEventArgs^ e)
    {
        timer1->Stop();
        if (!e->Cancelled)
        {
            if (nullptr == e->Error)
            {
                Application::Restart();
            }
            else
            {
                // Replace with your own error reporting or logging.
                MessageBox::Show(
                    "The update of the application encountered an " +
                    "error. Error message: {0}",
                    e->Error->Message);
            }
        }
        else
        {
            // Replace with your own error reporting or logging.
            MessageBox::Show(
                "The application update was cancelled because the update " +
                "server was unreachable. Please try again later.");
        }
    }

private:
    void timer1_Tick(Object^ sender, EventArgs^ e)
    {
        if (ApplicationDeployment::IsNetworkDeployed)
        {
            ApplicationDeployment::CurrentDeployment->UpdateAsyncCancel();
        }
    }

PermissionSet

For full access to the local computer. Associated enumeration: PermissionState.

.NET Framework
Available since 2.0
Return to top
Show: