异步,在Visual Studio 2010中等待

编程入门 行业动态 更新时间:2024-10-09 20:22:40
本文介绍了异步,在Visual Studio 2010中等待的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在VS2010和VS2012中都运行了以下代码,但VS2012只返回了响应.然后我搜索发现,需要在VS2010中启用异步并等待. 然后通过使用AsyncCtpLibrary dll参考,我已启用它.但是vs2010仍然不会返回响应.

I ran the below code in both VS2010 and VS2012, but VS2012 only return the response.Then i searched and found, needs to enable the async and await in VS2010. Then by using AsyncCtpLibrary dll reference, i have enabled it. But still vs2010 does not return the response.

static void Main(string[] args) { Task<string> task = GetCustomerDetails(); //PushCustomerDetails(); task.Wait(); var x = task.Result; } static async Task<string> GetCustomerDetails() { var httpClientHandler = new HttpClientHandler() { Credentials=new NetworkCredential("demo","demo"), }; var httpClient = new HttpClient(httpClientHandler); httpClient.DefaultRequestHeaders.Accept.Clear(); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var result1 = await httpClient.GetStringAsync("URL") return result1.ToString(); }

推荐答案

VS2010编译器不了解async/await.您需要安装异步CTP才能使用更新的编译器更新VS2010.

The VS2010 compiler has no knowledge of async/await. You need to install the Async CTP in order to update VS2010 with a newer compiler.

不幸的是,七年前,Visual Studio安装程序技术远远落后于当今. Async CTP安装程序的行为类似于VS更新,因此每次发布新的VS更新时,安装程​​序都会中断.然后,异步团队将不得不释放另一个安装程序,以使异步CTP再次运行.

Unfortunately, 7 years ago the Visual Studio installer technology was far behind where it is today. The Async CTP installer acted like a VS update, so it would break each time a new VS update was released. The async team would then have to release another installer for the Async CTP to work again.

AFAIK,此循环从未完成,并且最新的VS2010仍与异步CTP不兼容.因此,不再可以构建带有异步功能的VS2010构建机器.

AFAIK, this cycle was never completed, and the latest VS2010 remains incompatible with the Async CTP. Thus, it is no longer possible to construct a VS2010-with-async build machine.

更多推荐

异步,在Visual Studio 2010中等待

本文发布于:2023-11-23 23:15:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1623134.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Visual   Studio

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!