Export (0) Print
Expand All

ApplicationDeployment.DownloadFileGroupProgressChanged Event

Note: This event is new in the .NET Framework version 2.0.

Occurs when status information is available on a file download operation initiated by a call to DownloadFileGroupAsync.

Namespace: System.Deployment.Application
Assembly: System.Deployment (in system.deployment.dll)

public event DeploymentProgressChangedEventHandler DownloadFileGroupProgressChanged
/** @event */
public void add_DownloadFileGroupProgressChanged (DeploymentProgressChangedEventHandler value)

/** @event */
public void remove_DownloadFileGroupProgressChanged (DeploymentProgressChangedEventHandler value)

JScript supports the use of events, but not the declaration of new ones.

The DownloadFileGroupProgressChanged event is called on the main application thread. It is thread safe to call your application's Windows Forms controls directly within this callback.

Use the information supplied in DeploymentProgressChangedEventArgs to communicate progress information to your users.

The following code example downloads a group of Help files in the background. The example requires that you are deploying a Windows Forms application, and that this application contains a StatusStrip control, and it contains a ToolStripStatusPanelcontrol name downloadStatus.

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);
}

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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft