【发布时间】:2014-07-01 22:57:28
【问题描述】:
我有一个方法,代码如下:
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() 中的代码强制使用当前线程,或者我做错了。
我需要的流程是:
- 在从服务器获取数据之前显示加载掩码
- 从服务器获取数据(可能需要 3 秒)
- 然后退出任务并隐藏加载掩码。
有什么线索吗?
【问题讨论】:
标签: c# winforms task-parallel-library async-await