我被卡在了异步死锁中,无法找到正确的语法来解决它。我已经查看了几种不同的解决方案,但似乎无法完全弄清楚问题的原因。
我正在使用Parse作为后端,并尝试使用处理程序写入表格。我的处理程序大致如下:
然后它正在调用我的中间层:
尽管似乎会在
我正在使用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()
只会等待任务完成,然后返回正常操作。这不正确吗?
async
约定,特别是将SaveUserSignup
重命名为SaveUserSignupAsync
。 - Stephen Cleary