Asynchronous Programming with Async and Await

妖精的绣舞 提交于 2019-11-29 09:47:03
Gennady Vanin Геннадий Ванин

I am targeting the .NET 4.0 framework and am unsure as to any additional assemblies required

It is possible to run async/await code in .NET 4.0 without isntalling .NET 4.5, having included or referenced AsyncCtpLibrary.dll from Async CTP. It is impossible to install .NET 4.5 or Visual Studio 2012 on Windows XP and .NET 4.0 without .NET 4.5 installed is different from .NET 4.0 with installed .NET 4.5.
Read, for example, this discussion:

I disadvise to use Nuget on machine without .NET 4.5 for getting extensions for .NET 4.0 as it is really bringing compatible packs either for wrong .NET 4.5 or for .NET 4.0 from .NET 4.5 incompatible with .NET 4.0 without .NET 4.5

But your code has a syntax error

You should have return type Task<string[]>, instead of your Task<string>, in AccessTheWebAsync() method declaration, i.e. you should have written:

public async Task<string[]> AccessTheWebAsync(Class1 class1, Class2 class2)()  

instead of

public async Task<string> AccessTheWebAsync(Class1 class1, Class2 class2)()

in order for this method to return values of type string[]:

return listContents;//where listContents is declared as string[] type   

Update:
Checked that OP's code run after this correction on my true .NET 4.0 (without .NET 4.5 and VS2012) Windows XP machine with Async CTP

Why was my answer downvoted? anonymously...

It is obvious that if OP asks such question that he does not have .NET 4.5 installed. He will not be able to use Async Targeting Pack referencing "Async for .NET Framework 4, Silverlight 4 and 5, and Windows Phone 7.5 and 8 1.0.16" without installing VS2012, anв the latter is simply impossible on Wondows XP, with Nuget bring wrong packs in VS2010 incompatible and impossible to use on .NET 4.0 without .NET 4.5 installed

Checked it many times, in may contexts

Search for async in NuGet manager and install Microsoft Async to run async/await code in

YacineOuafi

You have to use BCL.Async library like descriped here : Using async without .net 4.5

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