这是我与服务器通信的异步方法:
public static Task<bool> ValidateEmail(string email)
{
var url = ServerBase + Resources + Authorization + "check_existence";
var queryString = SerializationHelper.CreateQueryString(new Dictionary<object, object> {{"email", email}});
try
{
return
HttpHelper.PostAsync(url, queryString, null).ContinueWith(
json => SerializationHelper.DeserializeValidationResponse(json.Result));
} catch (Exception e)
{
return TaskErrorHelper.Error<bool>(e);
}
}
DeserializeValidationResponse
未捕获序列化服务器响应(来自方法)时引发的异常。我究竟做错了什么?
更新:TaskErrorHelper.Error
代码:
internal static Task<T> Error<T>(Exception e)
{
var tcs = new TaskCompletionSource<T>();
tcs.SetException(e);
return tcs.Task;
}