Пример #1
0
        /// <summary>
        /// 确定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            Message = "开始下载更新文件...";
            wpControl.Visibility = Visibility.Hidden;
            progress.Visibility  = Visibility.Visible;
            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                var versionFileInfo     = VersionFileInfo.LoadServiceFileInfo();
                versionFileInfo.Message = message =>
                {
                    this.Message = message;
                };
                //下载更新包
                versionFileInfo.DownloadFile();
                Message = "下载已完成,即将为您更新!";

                this.Dispatcher.Invoke(new Action(() =>
                {
                    OKAction?.Invoke();//点触发外界OKAction一般用于退出程序,退出服务等资源释放操作。
                }));

                //等待彻底是放干净
                System.Threading.Thread.Sleep(500);

                //启动更新
                //var processStartInfo = new System.Diagnostics.ProcessStartInfo();
                var p = System.Diagnostics.Process.Start(System.IO.Path.GetFullPath(WorkPath.ExecPath + @"\AutoUpdate.exe"));
                p.WaitForExit();
                //Message = "即将为您启动程序...";
                //Message?.Invoke("即将为您启动程序...");
                //System.Threading.Thread.Sleep(100);

                //退出程序
                this.Dispatcher.Invoke(new Action(() =>
                {
                    Application.Current.Shutdown();
                }));

                if (versionFileInfo.IsZip)
                {
                    //启动程序
                    string appPath = System.IO.Path.GetFullPath(WorkPath.ExecPath + @"\" + versionFileInfo.AppID + ".exe");
                    System.Diagnostics.Process.Start(appPath);
                }
            });
        }
Пример #2
0
 public void OKClicked()
 {
     OKAction?.Invoke();
 }