Share via


CheckForUpdateCompletedEventArgs.MinimumRequiredVersion Property

Definition

Gets the minimum version that the user must have installed on the computer.

public:
 property Version ^ MinimumRequiredVersion { Version ^ get(); };
public Version MinimumRequiredVersion { get; }
member this.MinimumRequiredVersion : Version
Public ReadOnly Property MinimumRequiredVersion As Version

Property Value

A Version object expressing the earliest version that all users must install.

Examples

The following code example calls CheckForUpdateAsync, and forces an application update if MinimumRequiredVersion is greater than CurrentVersion.

ApplicationDeployment adCheckForUpdateAsyncMin;

private void CheckForUpdateAsyncMin()
{
    if (ApplicationDeployment.IsNetworkDeployed)
    {
        adCheckForUpdateAsyncMin = ApplicationDeployment.CurrentDeployment;
        adCheckForUpdateAsyncMin.CheckForUpdateCompleted += new CheckForUpdateCompletedEventHandler(adCheckForUpdateAsyncMin_CheckForUpdateCompleted);

        adCheckForUpdateAsyncMin.CheckForUpdate();
    }
}

void adCheckForUpdateAsyncMin_CheckForUpdateCompleted(object sender, CheckForUpdateCompletedEventArgs e)
{
    if (e.Error != null)
    {
        MessageBox.Show("Could not install application update. Please try again later,  or contact a system administrator.", "Application Update Error");
        return;
    }
    else if (e.Cancelled)
    {
        MessageBox.Show("The application update has been cancelled.", "Application Update Cancelled");
        return;
    }

    adCheckForUpdateAsyncMin = ApplicationDeployment.CurrentDeployment;
    if (e.MinimumRequiredVersion > adCheckForUpdateAsyncMin.CurrentVersion)
    {
        // Launch an install of the minimum required version. 
        adCheckForUpdateAsyncMin.UpdateCompleted += new AsyncCompletedEventHandler(adCheckForUpdateAsyncMin_UpdateCompleted);
        adCheckForUpdateAsyncMin.UpdateAsync();
    }
}

void adCheckForUpdateAsyncMin_UpdateCompleted(object sender, AsyncCompletedEventArgs e)
{
    // Alert user that update is complete.
    if (e.Error != null)
    {
        MessageBox.Show("Could not install application update. We will try and upgrade the application later.", "Application Update Error");
        return;
    }
    else if (e.Cancelled)
    {
        MessageBox.Show("The application update has been cancelled.", "Application Update Cancelled");
        return;
    }

    MessageBox.Show("The update was successful. Your application will now be restarted.", "Restart Application");
    Application.Restart();
}
Dim WithEvents ADCheckForUpdateAsyncMin As ApplicationDeployment

Private Sub CheckForUpdateAsyncMin()
    If (ApplicationDeployment.IsNetworkDeployed) Then
        ADCheckForUpdateAsyncMin = ApplicationDeployment.CurrentDeployment

        ADCheckForUpdateAsyncMin.CheckForUpdate()
    End If
End Sub


Private Sub ADCheckForUpdateAsyncMin_CheckForUpdateCompleted(ByVal sender As Object, ByVal e As CheckForUpdateCompletedEventArgs) Handles ADCheckForUpdateAsyncMin.CheckForUpdateCompleted
    If Not (e.Error Is Nothing) Then
        MessageBox.Show("Could not install application update. Please try again later,  or contact a system administrator.", "Application Update Error")
        Return
    Else
        If (e.Cancelled) Then
            MessageBox.Show("The application update has been cancelled.", "Application Update Cancelled")
            Return
        End If
    End If

    ADCheckForUpdateAsyncMin = ApplicationDeployment.CurrentDeployment
    If (e.MinimumRequiredVersion > ADCheckForUpdateAsyncMin.CurrentVersion) Then
        ' Launch an install of the minimum required version. 
        ADCheckForUpdateAsyncMin.UpdateAsync()
    End If
End Sub


Private Sub ADCheckForUpdateAsyncMin_UpdateCompleted(ByVal sender As Object, ByVal e As AsyncCompletedEventArgs) Handles ADCheckForUpdateAsyncMin.UpdateCompleted
    ' Alert user that update is complete.
    If Not (e.Error Is Nothing) Then
        MessageBox.Show("Could not install application update. We will try and upgrade the application later.", "Application Update Error")
        Return
    Else
        If (e.Cancelled) Then
            MessageBox.Show("The application update has been cancelled.", "Application Update Cancelled")
            Return
        End If
    End If

    MessageBox.Show("The update was successful. Your application will now be restarted.", "Restart Application")
    Application.Restart()
End Sub

Remarks

Applications can miss required updates when a user takes on a special assignment or is away from the computer for weeks or months. Use

MinimumRequiredVersion to determine if the user has not upgraded the application in a while, and has missed one or more required updates.

Applies to