ApplicationDeployment.UpdateAsync メソッド
アセンブリ: System.Deployment (system.deployment.dll 内)

Dim instance As ApplicationDeployment instance.UpdateAsync


アプリケーションの新しいバージョンを UpdateLocation で指定された場所に発行すると、そのアプリケーションは最新と見なされます。また、アプリケーションの配置マニフェストのバージョン番号は、ユーザーのコンピュータに現在インストールされているアプリケーションのバージョン番号よりも大きい番号になります。
更新のダウンロード中に、ClickOnce は、メイン アプリケーション スレッドで UpdateProgressChanged イベント ハンドラを発生させ、ダウンロードのステータスを通知します。非同期更新の完了時または例外発生時には、ClickOnce はメイン アプリケーション スレッドで UpdateCompleted イベントを発生させます。更新が成功したかどうかを確認するには、このイベントに提供された AsyncCompletedEventArgs を調べます。
UpdateAsync が例外をスローした場合、ClickOnce は UpdateCompleted を呼び出し、AsyncCompletedEventArgs の Error プロパティにスローされた例外を設定します。
UpdateAsync は、アプリケーション マニフェストに "optional" としてマークされていない配置内のすべてのファイルをダウンロードします。DownloadFileGroup メソッドまたは DownloadFileGroupAsync メソッドを使用すると、必要に応じてオプション ファイルをダウンロードできます。
このメソッドを呼び出したときに、ClickOnce によってアプリケーションの更新が既に自動的に開始されている場合があります。この場合、このメソッドの呼び出しによって、InvalidOperationException がスローされます。
配置内で 1 つ以上のファイルを更新しており、アプリケーション マニフェストを更新していない場合、InvalidDeploymentException が発生します。ほとんどの場合、アプリケーション マニフェストを再作成することによってこれを解決します。配置マニフェストまたはアプリケーション マニフェストの公開キーの署名が無効であったり、欠落したりしている場合にも、この例外が発生します。
更新で要求されるローカル コンピュータの信頼のレベルが、以前のバージョンよりも高い場合があります。アプリケーションが信頼されたアプリケーションの配置を使用している場合、共通言語ランタイムの信頼マネージャは配置マニフェストを調べ、有効な信頼ライセンスが含まれているかどうかを確認します。配置マニフェストに有効な信頼ライセンスが含まれていない場合、ClickOnce はインストールを中止し、TrustNotGrantedException をスローします。UpdateAsync によって、アプリケーションの実行に必要なアクセス許可を付与するかどうかをユーザーに確認するプロンプトが表示されることはありません。

アプリケーションの読み込み時に、新しい更新を利用できるかどうかを確認し、必須の更新の場合は非同期でインストールするコード例を次に示します。この例では、Windows フォーム アプリケーションを配置し、このアプリケーションに StatusStrip コントロールを含め、このコントロールに downloadStatus という名前の ToolStripStatusPanel コントロールを含める必要があります。
Private sizeOfUpdate As Long = 0 Dim WithEvents ADUpdateAsync As ApplicationDeployment Private Sub UpdateApplication() If (ApplicationDeployment.IsNetworkDeployed) Then ADUpdateAsync = ApplicationDeployment.CurrentDeployment ADUpdateAsync.CheckForUpdateAsync() End If End Sub Sub ADUpdateAsync_CheckForUpdateProgressChanged(ByVal sender As Object, ByVal e As DeploymentProgressChangedEventArgs) Handles ADUpdateAsync.CheckForUpdateProgressChanged DownloadStatus.Text = [String].Format("{0:D}K of {1:D}K downloaded.", e.BytesCompleted / 1024, e.BytesTotal / 1024) End Sub Sub ADUpdateAsync_CheckForUpdateCompleted(ByVal sender As Object, ByVal e As CheckForUpdateCompletedEventArgs) Handles ADUpdateAsync.CheckForUpdateCompleted If (e.Error IsNot Nothing) Then MessageBox.Show(("ERROR: Could not retrieve new version of the application. Reason: " + ControlChars.Lf + e.Error.Message + ControlChars.Lf + "Please report this error to the system administrator.")) Return Else If (e.Cancelled = True) Then MessageBox.Show("The update was cancelled.") End If End If ' Ask the user if they would like to update the application now. If (e.UpdateAvailable) Then sizeOfUpdate = e.UpdateSizeBytes If (Not e.IsUpdateRequired) Then Dim dr As DialogResult = MessageBox.Show("An update is available. Would you like to update the application now?", "Update Available", MessageBoxButtons.OKCancel) If (System.Windows.Forms.DialogResult.OK = dr) Then BeginUpdate() End If Else MessageBox.Show("A mandatory update is available for your application. We will install the update now, after which we will save all of your in-progress data and restart your application.") BeginUpdate() End If End If End Sub Private Sub BeginUpdate() ADUpdateAsync = ApplicationDeployment.CurrentDeployment ADUpdateAsync.UpdateAsync() End Sub Sub ADUpdateAsync_UpdateProgressChanged(ByVal sender As Object, ByVal e As DeploymentProgressChangedEventArgs) Handles ADUpdateAsync.UpdateProgressChanged Dim progressText As String = String.Format("{0:D}K out of {1:D}K downloaded - {2:D}% complete", e.BytesCompleted / 1024, e.BytesTotal / 1024, e.ProgressPercentage) DownloadStatus.Text = progressText End Sub Sub ADUpdateAsync_UpdateCompleted(ByVal sender As Object, ByVal e As AsyncCompletedEventArgs) Handles ADUpdateAsync.UpdateCompleted If (e.Cancelled) Then MessageBox.Show("The update of the application's latest version was cancelled.") Exit Sub Else If (e.Error IsNot Nothing) Then MessageBox.Show("ERROR: Could not install the latest version of the application. Reason: " + ControlChars.Lf + e.Error.Message + ControlChars.Lf + "Please report this error to the system administrator.") Exit Sub End If End If Dim dr As DialogResult = MessageBox.Show("The application has been updated. Restart? (If you do not restart now, the new version will not take effect until after you quit and launch the application again.)", "Restart Application", MessageBoxButtons.OKCancel) If (dr = System.Windows.Forms.DialogResult.OK) Then Application.Restart() End If End Sub
long sizeOfUpdate = 0; private void UpdateApplication() { if (ApplicationDeployment.IsNetworkDeployed) { ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment; ad.CheckForUpdateCompleted += new CheckForUpdateCompletedEventHandler(ad_CheckForUpdateCompleted); ad.CheckForUpdateProgressChanged += new DeploymentProgressChangedEventHandler(ad_CheckForUpdateProgressChanged); ad.CheckForUpdateAsync(); } } void ad_CheckForUpdateProgressChanged(object sender, DeploymentProgressChangedEventArgs e) { downloadStatus.Text = String.Format("Downloading: {0}. {1:D}K of {2:D}K downloaded.", GetProgressString(e.State), e.BytesCompleted/1024, e.BytesTotal/1024); } string GetProgressString(DeploymentProgressState state) { if (state == DeploymentProgressState.DownloadingApplicationFiles) { return "application files"; } else if (state == DeploymentProgressState.DownloadingApplicationInformation) { return "application manifest"; } else { return "deployment manifest"; } } void ad_CheckForUpdateCompleted(object sender, CheckForUpdateCompletedEventArgs e) { if (e.Error != null) { MessageBox.Show("ERROR: Could not retrieve new version of the application. Reason: \n" + e.Error.Message + "\nPlease report this error to the system administrator."); return; } else if (e.Cancelled == true) { MessageBox.Show("The update was cancelled."); } // Ask the user if they would like to update the application now. if (e.UpdateAvailable) { sizeOfUpdate = e.UpdateSizeBytes; if (!e.IsUpdateRequired) { DialogResult dr = MessageBox.Show("An update is available. Would you like to update the application now?\n\nEstimated Download Time: ", "Update Available", MessageBoxButtons.OKCancel); if (DialogResult.OK == dr) { BeginUpdate(); } } else { MessageBox.Show("A mandatory update is available for your application. We will install the update now, after which we will save all of your in-progress data and restart your application."); BeginUpdate(); } } } private void BeginUpdate() { ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment; ad.UpdateCompleted += new AsyncCompletedEventHandler(ad_UpdateCompleted); // Indicate progress in the application's status bar. ad.UpdateProgressChanged += new DeploymentProgressChangedEventHandler(ad_UpdateProgressChanged); } void ad_UpdateProgressChanged(object sender, DeploymentProgressChangedEventArgs e) { String progressText = String.Format("{0:D}K out of {1:D}K downloaded - {2:D}% complete", e.BytesCompleted / 1024, e.BytesTotal / 1024, e.ProgressPercentage); downloadStatus.Text = progressText; } void ad_UpdateCompleted(object sender, AsyncCompletedEventArgs e) { if (e.Cancelled) { MessageBox.Show("The update of the application's latest version was cancelled."); return; } else if (e.Error != null) { MessageBox.Show("ERROR: Could not install the latest version of the application. Reason: \n" + e.Error.Message + "\nPlease report this error to the system administrator."); return; } DialogResult dr = MessageBox.Show("The application has been updated. Restart? (If you do not restart now, the new version will not take effect until after you quit and launch the application again.)", "Restart Application", MessageBoxButtons.OKCancel); if (DialogResult.OK == dr) { Application.Restart(); } }
private: long sizeOfUpdate; private: void Form1_Load(Object^ sender, System::EventArgs^ e) { DoUpdate(); } public: void DoUpdate() { if (ApplicationDeployment::IsNetworkDeployed) { ApplicationDeployment^ currentAppDeployment = ApplicationDeployment::CurrentDeployment; currentAppDeployment->CheckForUpdateCompleted += gcnew CheckForUpdateCompletedEventHandler( this, &Form1::currentDeploy_CheckForUpdateCompleted); currentAppDeployment->CheckForUpdateAsync(); } } // If update is available, fetch it. void currentDeploy_CheckForUpdateCompleted(Object^ sender , CheckForUpdateCompletedEventArgs^ e) { if (nullptr != e->Error) { // Log error. return; } if (e->UpdateAvailable) { sizeOfUpdate = (long) e->UpdateSizeBytes; if (!e->IsUpdateRequired) { System::Windows::Forms::DialogResult updateDialogueResult = MessageBox::Show( "An update is available.Would you like to update the" + " application now?", "Update Available", MessageBoxButtons::OKCancel); if (System::Windows::Forms::DialogResult::OK == updateDialogueResult) { BeginUpdate(); } } else { BeginUpdate(); } } } void BeginUpdate() { ApplicationDeployment^ ad = ApplicationDeployment::CurrentDeployment; ad->UpdateCompleted += gcnew AsyncCompletedEventHandler( this, &Form1::CurrentDeployment_UpdateCompleted); // Indicate progress in the application's status bar. ad->UpdateProgressChanged += gcnew DeploymentProgressChangedEventHandler(this, &Form1::ad_ProgressChanged); ad->UpdateAsync(); } void CurrentDeployment_UpdateCompleted(Object^ sender, AsyncCompletedEventArgs^ e) { if (!e->Cancelled) { if (nullptr != e->Error) { System::Windows::Forms::DialogResult restartDialogueResult = MessageBox::Show( "The application has been updated. Restart?", "Restart Application", MessageBoxButtons::OKCancel); if (System::Windows::Forms::DialogResult::OK == restartDialogueResult) { Application::Restart(); } } else { // Replace with your own error reporting or logging. MessageBox::Show( "The application encountered an error in downloading" + " the latest update. Error: {0}", e->Error->Message); } } else { // Replace with your own error reporting or logging. MessageBox::Show("The update of the application's latest" + " version was cancelled."); } } void ad_ProgressChanged(Object^ sender, DeploymentProgressChangedEventArgs^ e) { String^ progressText = String::Format( "{0:D}K out of {1:D}K downloaded - {2:D}% complete", e->BytesCompleted / 1024, e->BytesTotal / 1024, e->ProgressPercentage); statusStrip1->Text = progressText; }


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からApplicationDeployment.UpdateAsync メソッドを検索する場合は、下記のリンクをクリックしてください。

- ApplicationDeployment.UpdateAsync メソッドのページへのリンク