によって 余小章 's 7年前.
480
定時更新範例
Task.Run(() => { while (true) { this.InstallUpdateSyncWithInfo(); Thread.Sleep(1000); if (this._isStop) { this._isStart = false; break; } } });
private void InstallUpdateSyncWithInfo() { UpdateCheckInfo info = null; if (ApplicationDeployment.IsNetworkDeployed) { ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment; try { info = ad.CheckForDetailedUpdate(); } catch (DeploymentDownloadException dde) { MessageBox.Show("The new version of the application cannot be downloaded at this time. \n\nPlease check your network connection, or try again later. Error: " + dde.Message); return; } catch (InvalidDeploymentException ide) { MessageBox.Show("Cannot check for a new version of the application. The ClickOnce deployment is corrupt. Please redeploy the application and try again. Error: " + ide.Message); return; } catch (InvalidOperationException ioe) { MessageBox.Show("This application cannot be updated. It is likely not a ClickOnce application. Error: " + ioe.Message); return; } if (info.UpdateAvailable) { Boolean doUpdate = true; if (!info.IsUpdateRequired) { DialogResult dr = MessageBox.Show("An update is available. Would you like to update the application now?", "Update Available", MessageBoxButtons.OKCancel); if (!(DialogResult.OK == dr)) { doUpdate = false; } } else { // Display a message that the app MUST reboot. Display the minimum required version. MessageBox.Show("This application has detected a mandatory update from your current " + "version to version " + info.MinimumRequiredVersion.ToString() + ". The application will now install the update and restart.", "Update Available", MessageBoxButtons.OK, MessageBoxIcon.Information); } if (doUpdate) { try { ad.Update(); MessageBox.Show("The application has been upgraded, and will now restart."); Application.Restart(); } catch (DeploymentDownloadException dde) { MessageBox.Show("Cannot install the latest version of the application. \n\nPlease check your network connection, or try again later. Error: " + dde); return; } } } } }
同步更新
Update
CheckForUpdate
非同步更新
大型更新,您可以透過 CheckForUpdateProgressChanged 和 UpdateProgressChanged 事件接收進度告知,並使用 ProgressChangedEventArgs 中的資訊告知使用者下載狀態
UpdateAsync
引發 UpdateCompleted 事件
CheckForUpdateAsync
引發 CheckForUpdateCompleted 事件
區域網路內
Share Folder
安裝FTP
Web Site
因為人品的關係,我從來沒成功過
IIS8.5 尚不支援
需安裝FrontPage Server
程式在執行期間,嘗試在背景尋找部署資訊清單檔,如果有可用的更新立即通知使用者是否更新
適合高頻寬網路連接,因為在低頻寬連接上啟動應用程式的延遲時間可能會非常久。
版本回復,一般使用者或系統管理員都可以將更新復原為之前的版本
預設的策略是在應用程式啟動前,嘗試找出並讀取部署資訊清單檔。使用此策略時,每次使用者啟動應用程式,應用程式就會嘗試找出並讀取部署資訊清單檔。如果有更新可用,就會下載並啟動更新。否則,就會啟動現有版本的應用程式
適合低頻寬網路連接或可能需要冗長下載時間的大型應用程式。
應用程式會在執行中時,嘗試在背景中尋找及讀取部署資訊清單檔。如果有可用的更新,下次使用者執行應用程式時,就會收到下載並安裝更新的提示。