ApplicationDeployment.DownloadFileGroupCompleted イベント

定義

ファイルのダウンロードが完了すると、メイン アプリケーション スレッドで発生します。Occurs on the main application thread when a file download is complete.

public:
 event System::Deployment::Application::DownloadFileGroupCompletedEventHandler ^ DownloadFileGroupCompleted;
public event System.Deployment.Application.DownloadFileGroupCompletedEventHandler DownloadFileGroupCompleted;
member this.DownloadFileGroupCompleted : System.Deployment.Application.DownloadFileGroupCompletedEventHandler 
Public Custom Event DownloadFileGroupCompleted As DownloadFileGroupCompletedEventHandler 

次のコード例では、ヘルプファイルのグループをバックグラウンドでダウンロードします。The following code example downloads a group of Help files in the background. この例では、 StatusStripコントロールを含む Windows フォームアプリケーションを配置し、このコントロールにという名前ToolStripStatusLabel downloadStatusのコントロールが含まれている必要があります。The example requires that you deploy a Windows Forms application that includes a StatusStrip control, and that this control contain a ToolStripStatusLabel control named downloadStatus.

void LaunchAppUpdate()
{
    if (ApplicationDeployment::IsNetworkDeployed)
    {
        ApplicationDeployment^ ad =
            ApplicationDeployment::CurrentDeployment;
        ad->UpdateCompleted +=
            gcnew AsyncCompletedEventHandler(this,
            &Form1::LaunchAppUpdate_UpdateCompleted);

        ad->UpdateAsync();
    }
}

void LaunchAppUpdate_UpdateCompleted(Object^ sender,
    AsyncCompletedEventArgs^ e)
{
    if (!e->Cancelled)
    {
        if (nullptr != e->Error)
        {
            System::Windows::Forms::DialogResult dr =
                MessageBox::Show(
                "The application has been updated. Restart?",
                "Restart Application",
                MessageBoxButtons::OKCancel);
            if (System::Windows::Forms::DialogResult::OK == dr)
            {
                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.");
    }
}
private void DownloadFileGroupAsync(string fileGroup)
{
    if (ApplicationDeployment.IsNetworkDeployed)
    {
        ApplicationDeployment deployment = ApplicationDeployment.CurrentDeployment;

        try
        {
            if (!deployment.IsFileGroupDownloaded(fileGroup))
            {
                deployment.DownloadFileGroupProgressChanged += new DeploymentProgressChangedEventHandler(deployment_DownloadFileGroupProgressChanged);
                deployment.DownloadFileGroupCompleted += new DownloadFileGroupCompletedEventHandler(deployment_DownloadFileGroupCompleted);

                deployment.DownloadFileGroupAsync(fileGroup);
            }
        }
        catch (InvalidOperationException ioe)
        {
            MessageBox.Show("This application is not a ClickOnce application. Error: " + ioe.Message);
            return;
        }
    }
}

void deployment_DownloadFileGroupProgressChanged(object sender, DeploymentProgressChangedEventArgs e)
{
    downloadStatus.Text = String.Format("Downloading file group {0}; {1:D}K of {2:D}K completed.", e.Group, e.BytesCompleted / 1024, e.BytesTotal / 1024);               
}

void deployment_DownloadFileGroupCompleted(object sender, DownloadFileGroupCompletedEventArgs e)
{
    if (e.Error != null)
    {
        downloadStatus.Text = "Could not download files. Will try again later.";
        return;
    }
    else if (e.Cancelled)
    {
        downloadStatus.Text = "The file download has been cancelled.";
        return;
    }

    downloadStatus.Text = String.Format("Download of file group {0} complete.", e.Group);
}
Dim WithEvents ADDownloadHelpFiles As ApplicationDeployment

Private Sub DownloadHelpFiles(ByVal GroupName As String)
    If (ApplicationDeployment.IsNetworkDeployed) Then
        ADDownloadHelpFiles = ApplicationDeployment.CurrentDeployment

        If ADDownloadHelpFiles.IsFirstRun Then
            Try
                If Not ADDownloadHelpFiles.IsFileGroupDownloaded(GroupName) Then
                    ADDownloadHelpFiles.DownloadFileGroupAsync(GroupName)
                End If
            Catch ioe As InvalidOperationException
                MessageBox.Show("This application is not a ClickOnce application.")
                Return
            End Try
        End If
    End If
End Sub

Private Sub ADDownloadHelpFiles_DownloadFileGroupProgressChanged(ByVal sender As Object, ByVal e As DeploymentProgressChangedEventArgs) Handles ADDownloadHelpFiles.DownloadFileGroupProgressChanged
    DownloadStatus.Text = String.Format("Downloading file group {0}; {1:D}K of {2:D}K completed.", e.Group, e.BytesCompleted / 1024, e.BytesTotal / 1024)
End Sub

Private Sub ADDownloadHelpFiles_DownloadFileGroupCompleted(ByVal sender As Object, ByVal e As DownloadFileGroupCompletedEventArgs) Handles ADDownloadHelpFiles.DownloadFileGroupCompleted
    DownloadStatus.Text = String.Format("Download of file group {0} complete.", e.Group)
End Sub

注釈

DownloadFileGroupCompletedイベントは、メインアプリケーションスレッドで呼び出されます。The DownloadFileGroupCompleted event is called on the main application thread. アプリケーションの Windows フォームコントロールをこのコールバック内で直接呼び出すには、スレッドセーフである必要があります。It is thread safe to call your application's Windows Forms controls directly within this callback.

このコールErrorバックにAsyncCompletedEventArgs提供されたのプロパティを確認します。Check the Error property of the AsyncCompletedEventArgs supplied to this callback. このプロパティがnullの場合、ダウンロードは正常に実行されてnullいます。そうでない場合、インストールは成功しませんでした。また、 Errorインストールエラーの詳細については、プロパティを参照してください。If this property is null, the download was successful; if it is not null, the installation did not succeed, and you can find more information about the installation failure through the Error property.

適用対象