Off*_*nez 2 .net c# async-await windows-8
我今天遇到了一个奇怪的问题......我的代码在c#中的await方法上运行(没有错误或者是......).
user = await JsonConvert.DeserializeObjectAsync<User>(content);
Run Code Online (Sandbox Code Playgroud)
但当我删除"等待"我的代码工作...
user = JsonConvert.DeserializeObjectAsync<User>(content).Result;
Run Code Online (Sandbox Code Playgroud)
我的HttpClient遇到了同样的问题:
作品
using (HttpResponseMessage response = client.PostAsync(url, posts).Result)
Run Code Online (Sandbox Code Playgroud)
不行
using (HttpResponseMessage response = await client.PostAsync(url, posts))
Run Code Online (Sandbox Code Playgroud)
问题是前一天没有,如果我将我的代码放在另一个类中,它可以正常工作
输出:
The thread 0xe44 has exited with code 259 (0x103).
The thread 0x81c has exited with code 259 (0x103).
The thread 0x150c has exited with code 259 (0x103).
The thread 0x1660 has exited with code 259 (0x103).
Run Code Online (Sandbox Code Playgroud)
我重建了,我还有那个问题.
有人知道答案吗?