ApplicationDeployment.CheckForUpdate Método
Definição
Verifica UpdateLocation para determinar se uma nova atualização está disponível.Checks UpdateLocation to determine whether a new update is available.
Sobrecargas
| CheckForUpdate() |
Verifica UpdateLocation para determinar se uma nova atualização está disponível.Checks UpdateLocation to determine whether a new update is available. |
| CheckForUpdate(Boolean) |
Verifica UpdateLocation para determinar se uma nova atualização está disponível.Checks UpdateLocation to determine whether a new update is available. |
CheckForUpdate()
Verifica UpdateLocation para determinar se uma nova atualização está disponível.Checks UpdateLocation to determine whether a new update is available.
public:
bool CheckForUpdate();
public bool CheckForUpdate ();
member this.CheckForUpdate : unit -> bool
Public Function CheckForUpdate () As Boolean
Retornos
true se uma nova atualização estiver disponível; caso contrário, false.true if a new update is available; otherwise, false.
Exceções
O ClickOnce lançará essa exceção imediatamente se você chamar o CheckForUpdate() método enquanto uma atualização já estiver em andamento.ClickOnce throws this exception immediately if you call the CheckForUpdate() method while an update is already in progress.
Não é possível baixar o manifesto de implantação.The deployment manifest cannot be downloaded.
O manifesto de implantação foi corrompido.The deployment manifest is corrupted. Você provavelmente precisará reimplantar o aplicativo para corrigir este problema.You will likely need to redeploy the application to fix this problem.
Exemplos
O exemplo de código a seguir verifica uma atualização de aplicativo; Se houver um disponível, ele o instalará de forma síncrona.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();
}
}
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);
}
}
}
}
Private Sub InstallUpdateSync()
If (ApplicationDeployment.IsNetworkDeployed) Then
Dim updateAvailable As Boolean = False
Dim AD As ApplicationDeployment = ApplicationDeployment.CurrentDeployment
Try
updateAvailable = AD.CheckForUpdate()
Catch dde As DeploymentDownloadException
' This exception occurs if a network error or disk error occurs
' when downloading the deployment.
MessageBox.Show("The application cannot check for the existence of a new version at this time. " & ControlChars.Lf & ControlChars.Lf & "Please check your network connection, or try again later. Message: " & dde.Message)
Exit Sub
Catch ide As InvalidDeploymentException
MessageBox.Show("The application cannot check for an update. The ClickOnce deployment is corrupt. Please redeploy the application and try again. Message: " & ide.Message)
Exit Sub
Catch ioe As InvalidOperationException
MessageBox.Show("The application cannot check for an update. This most likely happened because the application is already updating. Message: " & ioe.Message)
Exit Sub
End Try
If (updateAvailable) Then
Try
AD.Update()
MessageBox.Show("The application has been upgraded, and will now restart.")
Application.Restart()
Catch dde As DeploymentDownloadException
MessageBox.Show("Cannot install the latest version of the application. " + ControlChars.Lf + ControlChars.Lf + "Please check your network connection, or try again later.")
End Try
End If
End If
End Sub
Comentários
O CheckForUpdate método compara a versão da implantação instalada no momento com a versão especificada no manifesto de implantação encontrado em UpdateLocation .The CheckForUpdate method compares the version of the currently installed deployment with the version specified in the deployment manifest found at UpdateLocation. Se a versão no servidor for diferente da versão instalada, ela retornará true .If the version on the server is different from the installed version, it returns true.
Esse método será bloqueado até que a verificação seja concluída.This method will block until the check has completed. Para verificar uma atualização de forma assíncrona, use o CheckForUpdateAsync método.To check for an update asynchronously, use the CheckForUpdateAsync method instead.
Observação
Se o CheckForUpdate descobrir que uma atualização está disponível e o usuário optar por não instalá-la, o ClickOnce solicitará ao usuário que uma atualização esteja disponível na próxima vez em que o aplicativo for executado.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. Não é possível desabilitar essa solicitação.There is no way to disable this prompting. (Se o aplicativo for uma atualização necessária, o ClickOnce irá instalá-lo sem avisar.)(If the application is a required update, ClickOnce will install it without prompting.)
Confira também
Aplica-se a
CheckForUpdate(Boolean)
Verifica UpdateLocation para determinar se uma nova atualização está disponível.Checks UpdateLocation to determine whether a new update is available.
public:
bool CheckForUpdate(bool persistUpdateCheckResult);
public bool CheckForUpdate (bool persistUpdateCheckResult);
member this.CheckForUpdate : bool -> bool
Public Function CheckForUpdate (persistUpdateCheckResult As Boolean) As Boolean
Parâmetros
- persistUpdateCheckResult
- Boolean
Se false, a atualização será aplicada silenciosamente e nenhuma caixa de diálogo será exibida.If false, the update will be applied silently and no dialog box will be displayed.
Retornos
true se uma nova atualização estiver disponível; caso contrário, false.true if a new update is available; otherwise, false.