Ich gehe durch dieses Tutorial zur asynchronen Programmierung in C# und bin auf einen Fehler gestoßen, ich bin mir nicht sicher, wie zu lösen. Hier ist der Link: http://msdn.microsoft.com/en-us/library/hh191443.aspx und der Fehler ist:Asynchrone Programmierung mit Async und erwarte
Cannot find all types required by the 'async' modifier.
Are you targeting the wrong framework version, or missing a reference to an assembly?
ich das .NET 4.0 Framework bin Targeting und bin nicht sicher, alle weiteren Baugruppen erforderlich. Hier
ist der Code:
public async Task<string> AccessTheWebAsync(Class1 class1, Class2 class2)
{
// GetStringAsync returns a Task<string>. That means that when you await the
// task you'll get a List<string> (urlContents).
Task<string[]> 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<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;
}
Asynchron - erwarten ist von .NET Framework 4.5, nicht 4 –
@CuongLe, 'async/await' ist von' C# -5.0' aber ich benutze es in .NET 4.0 installiert haben 'Async CTP' b/c Ich kann .NET-4.5 (oder VS2012) nicht unter Windows XP (VS2010) installieren. Stellen Sie sich die Erweiterung als echte .NET-4.0 vor, nicht die, die nur mit .NET-4.5 kommt. –