请有人能够确认我是否正确理解了Async await关键字吗?(使用CTP的第3版)
到目前为止,我已经解决了在方法调用之前插入await关键字基本上做了两件事,A.它创建一个立即返回和B.它创建一个"延续",在完成异步方法调用时调用.在任何情况下,continuation都是该方法的代码块的其余部分.
所以我想知道的是,这两位代码在技术上是等价的,如果是这样,这基本上意味着await关键字与创建ContinueWith Lambda相同(即:它基本上是一个编译器快捷方式)?如果没有,有什么区别?
bool Success =
await new POP3Connector(
"mail.server.com", txtUsername.Text, txtPassword.Text).Connect();
// At this point the method will return and following code will
// only be invoked when the operation is complete(?)
MessageBox.Show(Success ? "Logged In" : "Wrong password");
Run Code Online (Sandbox Code Playgroud)
VS
(new POP3Connector(
"mail.server.com", txtUsername.Text, txtPassword.Text ).Connect())
.ContinueWith((success) =>
MessageBox.Show(success.Result ? "Logged In" : "Wrong password"));
Run Code Online (Sandbox Code Playgroud)