string VariableA
string VariableB
string VariableC
void Main(){
run((string result){A= result;});
run((string result){B = result;});
run((string result){C = result;});
Task.Run(async ()=>{
while (A == null)
await Task.delay(100);
})
... unreachable code
... when breaking here >> t.Result holds a value but the owner task is Blocked in task window
}
void run(Action<string> action){
Task.Run( async ()=>{ Some Operations; } )
.ContinueWith((t, o) => {
Application.Current.Dispatcher.Invoke(() => {
action(t.Result);
}) ;
}, SynchronizationContext.Current);
}
这是永远的..并且我调试一次..我发现任务结果已检索到,但无法通过继续动作传递..它永远为while循环提供动力
。
SynchronizationContext.Current用于ContinueWith
答案 0 :(得分:0)
从构造函数中调用Run Initializing the tasks
是犯罪。
只需将其移至控件的构造器即可。