c# - Asynchronous Programming with Async and Await -


i'm walking through tutorial on how program asynchronously in c# , have come across error i'm not sure how resolve. here's link: http://msdn.microsoft.com/en-us/library/hh191443.aspx , error is:

cannot find types required 'async' modifier.   targeting wrong framework version, or missing reference assembly?    

i targeting .net 4.0 framework , unsure additional assemblies required.

here code:

public async task<string> accessthewebasync(class1 class1, class2 class2) {   // getstringasync returns task<string>. means when await    // task you'll list<string> (urlcontents).   task<string[]> listtask = getlist(class1);    // send message task    // can work here doesn't rely on string getstringasync.   //compareservice();    // await operator suspends accessthewebasync.    //  - accessthewebasync can't continue until getstringtask complete.    //  - meanwhile, control returns caller of accessthewebasync.    //  - control resumes here when getstringtask complete.     //  - await operator retrieves string result getstringtask.    string[] listcontents = await listtask;    // return statement specifies integer result.    // methods awaiting accessthewebasync retrieve length value.    return listcontents; }  public task<string[]> getlist(class1 class1) {     var taskarray = task<string[]>.factory.startnew(() => generateresults(class1));     return taskarray; } public string[] generateresults(class1 class1) {     string[] results = new string[2];     results[1] = "";     results[2] = "";     return results; } 

i targeting .net 4.0 framework , unsure additional assemblies required

it possible run async/await code in .net 4.0 without isntalling .net 4.5, having included or referenced asyncctplibrary.dll async ctp. impossible install .net 4.5 or visual studio 2012 on windows xp , .net 4.0 without .net 4.5 installed different .net 4.0 installed .net 4.5.
read, example, discussion:

i disadvise use nuget on machine without .net 4.5 getting extensions .net 4.0 bringing compatible packs either wrong .net 4.5 or .net 4.0 .net 4.5 incompatible .net 4.0 without .net 4.5

but code has syntax error

you should have return type task<string[]>, instead of task<string>, in accessthewebasync() method declaration, i.e. 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 method return values of type string[]:

return listcontents;//where listcontents declared string[] type    

update:
checked op's code run after correction on true .net 4.0 (without .net 4.5 , vs2012) windows xp machine async ctp

why answer downvoted? anonymously...

it obvious if op asks such question not have .net 4.5 installed. not able use async targeting pack referencing "async .net framework 4, silverlight 4 , 5, , windows phone 7.5 , 8 1.0.16" without installing vs2012, anŠ² latter impossible on wondows xp, nuget bring wrong packs in vs2010 incompatible , impossible use on .net 4.0 without .net 4.5 installed

checked many times, in may contexts


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -