VAA*_*AAA 3 c# winforms task-parallel-library async-await
我有一个方法,使用以下代码:
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);
});
Run Code Online (Sandbox Code Playgroud)
那么,我如何强制ContinueWith()强制使用当前线程的代码,或者我做错了.
我需要的过程是:
任何线索?
传递TaskScheduler.FromCurrentSynchronizationContext()给ContinueWith()......
.ContinueWith((task) => {
// hide loading mas
Core.HideLoadingMask();
if (frm != null) this.Panel.Controls.Add(frm);
}, TaskScheduler.FromCurrentSynchronizationContext());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1464 次 |
| 最近记录: |