Async, Await in visual studio 2010

拜拜、爱过 提交于 2019-12-20 05:12:39

问题


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();
    }

回答1:


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.

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, 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.



来源:https://stackoverflow.com/questions/45116931/async-await-in-visual-studio-2010

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!