System.Windows.Application.Current.Dispatcher.BeginInvoke

System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                           {
                               if (True)
                               {
                                  
                               }
                           }));

异步方法

Task.Factory.StartNew(() =>
            {
                ViewModel.ToDownload();
            });

Task.Factory.StartNew<Update.UpdateConfig>(() =>
                {
                    Thread.Sleep(3000);
                    bool isnew = Update.UpdateService.CheckNewVersion();
                    if (isnew)
                    {
                        UpdateConfig config=Update.UpdateService.GetNewVersion();
                        HasChecked = true;
                        return config;
                    }
                    return null;
                }, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default)
                .ContinueWith((e) =>
                {
                    if (e.Exception == null)
                    {
                        if (e.Result != null)
                        {
                            Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                            {
                                //弹出更新窗口
                                Update.UpdateService.ShowUpdateWindowLoadComplete(e.Result, () =>
                                {
                                    return true;
                                }, Application.Current.MainWindow);
                            }));
                        }
                    }
                });

上一篇:简单的使用AngularJS的解析JSON


下一篇:从零开始学 Java - Windows 下安装 Eclipse