c# – Task.Continuewith(在当前线程上)
发布时间:2020-12-16 02:01:44 所属栏目:百科 来源:网络整理
导读:我有一个方法,使用以下代码: object frm = null;// shows the overlay loading maskCore.ShowLoadingMask("Please wait...");// start taskTask.Factory.StartNew(() = { // go to server and get the data var employee = new Data.Entities.Employee(empl
我有一个方法,使用以下代码:
object frm = null; // shows the overlay loading mask Core.ShowLoadingMask("Please wait..."); // start task Task.Factory.StartNew(() => { // go to server and get the data var employee = new Data.Entities.Employee(employeeId); // instantiate the class type (reflection) frm = Activator.CreateInstance(type,employee ); }).ContinueWith((task) => { // hide loading mas Core.HideLoadingMask(); if (frm != null) this.Panel.Controls.Add(frm); }); 那么,我如何强制使用ContinueWith()中的代码强制使用当前线程,或者我可能做错了. 我需要的过程是: >从服务器获取数据之前显示加载掩码 任何线索? 解决方法
将
TaskScheduler.FromCurrentSynchronizationContext() 传递给ContinueWith()……
.ContinueWith((task) => { // hide loading mas Core.HideLoadingMask(); if (frm != null) this.Panel.Controls.Add(frm); },TaskScheduler.FromCurrentSynchronizationContext()); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 无法使用pgAdmin将PostgreSQL连接到远程数据库
- ruby-on-rails – 无法运行rake db:使用Railscast示例在Ra
- C#设计模式之Builder生成器模式解决带老婆配置电脑问题实例
- PostgreSQL 学习一 安装和入门
- database – 如何在Postgresql中创建返回动态列名的查询?
- 正则表达式 – 删除/替换bash中的html标签
- c – gcc -lpthread无效
- c# – 将datatable转换为excel 2007(.xlsx)
- TQ2440 学习笔记—— 7、NOR Flash 和 NAND Flash
- c – 模板忽略[[nodiscard]]属性