Note that there are some explanatory texts on larger screens.

plurals
  1. POAsynchronous Programming with Async and Await
    primarykey
    data
    text
    <p>I'm walking through this tutorial on how to program asynchronously in c# and have come across an error I'm not sure how to resolve. Here's the link: <a href="http://msdn.microsoft.com/en-us/library/hh191443.aspx">http://msdn.microsoft.com/en-us/library/hh191443.aspx</a> and the error is: </p> <pre><code>Cannot find all types required by the 'async' modifier. Are you targeting the wrong framework version, or missing a reference to an assembly? </code></pre> <p>I am targeting the .NET 4.0 framework and am unsure as to any additional assemblies required. </p> <p>Here is the code:</p> <pre><code>public async Task&lt;string&gt; AccessTheWebAsync(Class1 class1, Class2 class2) { // GetStringAsync returns a Task&lt;string&gt;. That means that when you await the // task you'll get a List&lt;string&gt; (urlContents). Task&lt;string[]&gt; listTask = GetList(class1); // send message task // You can do work here that doesn't rely on the string from GetStringAsync. //CompareService(); // The await operator suspends AccessTheWebAsync. // - AccessTheWebAsync can't continue until getStringTask is complete. // - Meanwhile, control returns to the caller of AccessTheWebAsync. // - Control resumes here when getStringTask is complete. // - The await operator then retrieves the string result from getStringTask. string[] listContents = await listTask; // The return statement specifies an integer result. // Any methods that are awaiting AccessTheWebAsync retrieve the length value. return listContents; } public Task&lt;string[]&gt; GetList(Class1 class1) { var taskArray = Task&lt;string[]&gt;.Factory.StartNew(() =&gt; GenerateResults(class1)); return taskArray; } public string[] GenerateResults(Class1 class1) { string[] results = new string[2]; results[1] = ""; results[2] = ""; return results; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload