private void button3_Click(object sender, EventArgs e)
{
try
{
if (!(ApplicationDeployment.IsNetworkDeployed)) return; //確定此程式是否為ClickOnce所部署的程式
System.Deployment.Application.ApplicationDeployment obj = ApplicationDeployment.CurrentDeployment;//取得目前使用者的版本資訊
if (ApplicationDeployment.CurrentDeployment.CheckForUpdate())//比對伺服器上的版本
{
if (MessageBox.Show("發現新的版本,是否確定更版", "更版通知",
MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
obj.UpdateProgressChanged += new DeploymentProgressChangedEventHandler(obj_UpdateProgressChanged);
obj.UpdateCompleted += new AsyncCompletedEventHandler(obj_UpdateCompleted);
obj.UpdateAsync();
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void obj_UpdateProgressChanged(object sender, DeploymentProgressChangedEventArgs e)
{
Progress_Update.Value = e.ProgressPercentage;
Application.DoEvents();
}
private void obj_UpdateCompleted(object sender, AsyncCompletedEventArgs e)
{
Application.Restart();
}