有人可以解释一下异步模式中的usingawait和 the之间有什么区别,以及我将在哪里使用它们?Result
public static async Task<string> GetVersion(int port, string method)
{
var client = new HttpClient();
client.BaseAddress = new Uri("http://localhost:" + port);
return client.GetStringAsync("/test").Result; //<===============this versus
return await client.GetStringAsync("/test").ConfigureAwait(false);//<=====this
}
Run Code Online (Sandbox Code Playgroud)
调用Result将阻塞当前线程,直到操作完成。当异步操作完成时,返回await给调用者并继续该方法的其余部分。