C# Windows Phone异步呼叫终止

C# Windows Phone异步呼叫终止,c#,asynchronous,windows-phone,terminate,C#,Asynchronous,Windows Phone,Terminate,我正在为一个小型windows phone应用程序创建一个Rest通信接口,因为您不能调用SOAP web服务。该接口很简单,使用JsonConverter解析json响应 代码如下所示 public class Communicate<RequestType,ResposeType> where ResposeType:class where RequestType :class { public async Task< ResposeType>

我正在为一个小型windows phone应用程序创建一个Rest通信接口,因为您不能调用SOAP web服务。该接口很简单,使用JsonConverter解析json响应

代码如下所示

    public class Communicate<RequestType,ResposeType> where ResposeType:class  where RequestType :class
{

     public async Task< ResposeType> CommunicateSvr(RequestType _parameter,string methodName,string serverIp)
     {
         String reqData = JsonConvert.SerializeObject(_parameter);

         HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, serverIp+methodName);
         request.Content = new StringContent(reqData, Encoding.UTF8, "application/json");

         HttpClient client = new HttpClient();
         client.DefaultRequestHeaders
             .Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

         HttpResponseMessage response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);



         if (response.StatusCode == HttpStatusCode.OK)
             return JsonConvert.DeserializeObject<ResposeType>(await response.Content.ReadAsStringAsync());
         else
             throw new Exception("Error connecting to " + serverIp+methodName+ " ! Status: " + response.StatusCode);

     }
}
线程结束、终止,应用程序似乎停止。仍在运行,但未执行任何操作。我一个接一个地设置了两个断点,但第二个断点从未到达。我不知道怎么了,我在网上搜索了很多次,但没有发现任何有用的东西。提前感谢,等待您的回复

在输出窗口上,我收到以下消息:

The thread 0xdec has exited with code 259 (0x103).
The thread 0x2180 has exited with code 259 (0x103).
你可能是我在博客上解释的。在这种情况下,UI线程将死锁(而不是退出)


最好的解决方法是将
Wait
Result
更改为
Wait

您是在调用
Wait
还是
Result
进一步调用堆栈?或者您是从
async void
方法调用它的?这是我调用公共登录登录(用户名用户){Communicate comm=new Communicate();Login\u loginRes=comm.CommunicateSvr(用户,“Login”,ServiceIP)。结果;返回_loginRes;}谢谢@StephenCleary这就是问题所在,我在上层堆栈中同步调用了它。
The thread 0xdec has exited with code 259 (0x103).
The thread 0x2180 has exited with code 259 (0x103).