我有一个带以下代码的方法:
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秒钟)。
- 在此之后退出任务,并隐藏加载遮罩。
有什么线索吗?