我被困在异步死锁,我找不出正确的语法来解决它。我看过几种不同的解决方案,但似乎无法弄清楚是什么导致了这个问题。异步等待处理程序死锁
我使用Parse作为后端,并尝试使用处理程序写入表。我的处理程序看起来像:
public class VisitorSignupHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
//Get the user's name and email address
var UserFullName = context.Request.QueryString["name"].UrlDecode();
var UserEmailAddress = context.Request.QueryString["email"].UrlDecode();
//Save the user's information
var TaskToken = UserSignup.SaveUserSignup(UserFullName, UserEmailAddress);
TaskToken.Wait();
....
}
public bool IsReusable { get { return false; } }
}
然后,它呼唤我的中间层:
public static class UserSignup
{
public static async Task SaveUserSignup(string fullName, string emailAddress)
{
//Initialize the Parse client with the Application ID and the Windows key
ParseClient.Initialize(AppID, Key);
//Create the object
var UserObject = new ParseObject("UserSignup")
{
{"UserFullName", fullName},
{"UserEmailAddress", emailAddress}
};
//Commit the object
await UserObject.SaveAsync();
}
}
尽管这似乎是陷入在Wait()
。我的印象是,Wait()
只是等待任务完成,然后返回到正常操作。这是不正确的?
谢谢!我在发布之前先阅读您的博客,但无法完全弄清楚语法。这很好。欣赏它。 –
不客气!附:给[TAP文档](http://msdn.microsoft.com/en-us/library/hh873175.aspx)一个很好的阅读;这里有一些'async'约定,特别是将'SaveUserSignup'重命名为'SaveUserSignupAsync'。 –