I am trying to use Async and Await when making a web request and am finding that it never gets past the await line. I am doing this from a Metro app, but I also verified the problem in a winforms app.
public async Task<string> DoSomething()
{
string url = "http://imgur.com/gallery/VcBfl.json";
HttpWebRequest request = HttpWebRequest.CreateHttp(url);
var ws = await request.GetResponseAsync();
return ws.ResponseUri.ToString(); ;
}
If I don't use await and instead perform a synchronous wait, it works, but I need this to run asynchronously.
What am I missing in this code that is causing the await to never return?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…