首页 > 技术文章 > System.Windows.Application.Current.Dispatcher.BeginInvoke

m7777 2015-10-14 13:36 原文

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);
                            }));
                        }
                    }
                });

推荐阅读