我無法讓“continueWith”將動作作為引數使用,它什么也不做,也沒有錯誤。
private async void BaumPage_Appearing(object sender, EventArgs e)
{
if ( App.db_objekte == null )
{
Action<Task> someMethod;
someMethod = delegate (Task t) { Console.WriteLine("hello world"); };
MsgBoxWithAction("DB Empty.", someMethod);
return;
}
}
public void MsgBoxWithAction(string sMsg, Action<Task> a)
{
DisplayAlert("Fehler", sMsg, "OK").ContinueWith(t => a);
}
`
uj5u.com熱心網友回復:
我更喜歡使用 async-await 而不是繼續使用,這更有意義,因為代碼看起來不是很混亂,更不用說它也更容易理解。
你上面提到的代碼可以很容易地轉換成類似的東西:
public async void MsgBoxWithAction(string sMsg, Action<Task> a)
{
await DisplayAlert("Fehler", sMsg, "OK");
a();
}
有關 async-await 如何優于 ContinueWith 的基本比較,請查看此處
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/411873.html
標籤:
下一篇:渲染組件后API呼叫回傳影像
