ApplicationDeployment.IsNetworkDeployed 属性

定义

获取一个值,该值指示当前应用程序是否为 ClickOnce 应用程序。Gets a value indicating whether the current application is a ClickOnce application.

public:
 static property bool IsNetworkDeployed { bool get(); };
public static bool IsNetworkDeployed { get; }
member this.IsNetworkDeployed : bool
Public Shared ReadOnly Property IsNetworkDeployed As Boolean

属性值

Boolean

true 如果这是 ClickOnce 应用程序,则为;否则为 falsetrue if this is a ClickOnce application; otherwise, false.

示例

下面的代码示例 CurrentDeployment 首先使用检索, IsNetworkDeployed 以确保引用不是 nullThe following code example retrieves CurrentDeployment by using IsNetworkDeployed first to ensure that the reference is not null.

public:
    void LaunchUpdate()
    {
        if (ApplicationDeployment::IsNetworkDeployed)
        {
            ApplicationDeployment^ launchAppDeployment =
                ApplicationDeployment::CurrentDeployment;
            // Launch synchronous or asynchronous update.
        }
    }
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();
        }
    }
}

注解

如果你希望应用程序在 ClickOnce 部署的内部和外部运行 (例如,如果你需要在部署之前在本地计算机上调试应用程序) ,请 IsNetworkDeployed 在访问属性之前进行测试 CurrentDeploymentIf you want your application to run both inside and outside of a ClickOnce deployment (for example, if you need to debug your application on the local computer before deploying it), test IsNetworkDeployed before accessing the CurrentDeployment property.

IsNetworkDeployedtrue无论应用程序是联机安装还是托管,无论该应用程序是从网站、文件共享还是 cd-rom 安装,都将返回。IsNetworkDeployed will return true regardless of whether the application is installed or hosted online, and regardless of whether it was installed from a Web site, file share, or CD-ROM.

适用于