作者:VB.NET开发
项目:System.Deployment.Applicatio
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