问题描述
我有我使用调用一个URI以下code:
I have the following code that I'm using to call a uri:
var uri = string.Format("Helpers/ProfileList/Online/?locationId=0&skip=0&take={0}", numProfiles);
HttpResponseMessage response = await client.GetAsync(uri);
response.EnsureSuccessStatusCode();
URI是在自定义的Web API的URI指向(我可以调试和跟进)。然而,当在API的最后一个return语句被调用,好像没有什么改变。它应该去 response.EnsureSuccessStatus code();
线,但事实并非如此。它只是似乎挂。
The uri is pointing at a custom web api uri (which I can debug and follow through). However, when the last return statement in the api has been called, nothing seems to happen. It should go to the response.EnsureSuccessStatusCode();
line, but it's not. It just seems to be hanging.
推荐答案
我的蜘蛛侠,感觉告诉我,进一步您的通话堆栈的code是返回的任务阻塞,如任务.Wait
或任务< T>。结果
。默认情况下,这将导致死锁一>,我在我的博客解释。
My spidey-sense tells me that further up your call stack your code is blocking on a returned task, e.g., Task.Wait
or Task<T>.Result
. By default, this will cause a deadlock that I explain on my blog.
要解决这个问题,替换 Task.Wait
和任务&LT; T&GT;。结果
与等待
。
To fix it, replace Task.Wait
and Task<T>.Result
with await
.
这篇关于如何从吊停止HttpClient.GetAsync(URI)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!