我在想,几乎所有使用ContinueWith
的代码都可以用async/await
重构,但这个有点难。什么我想转换草图:async/await vs ContinueWith
// UI unit testing: close the message box in 1s
Task.Delay(1000).ContinueWith((t) =>
{
SendKeys.Send("{ENTER}");
}, TaskScheduler.FromCurrentSynchronizationContext());
MessageBox.Show("Hello!");
Debug.Print("continue after a message box");
如何将其与async/await
做什么?
那么,你有什么尝试? –
它不能,因为你从来没有真正“等待”那秒通过。 'ContinueWith'通常是任务中的'async' /'await'的替代品(尽管难度较大),但事实并非如此。 –
@Mario,我展示了我试过的,不是吗?这不像我问“如何显示消息框并将密钥异步发送给它”,是吗? – avo