我陷入了异步死锁,无法找出正确的语法来修复它。我查看了几种不同的解决方案,但似乎无法完全弄清楚导致问题的原因。
我使用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()
只需等待任务完成,然后恢复正常操作即可。这不正确吗?