我已经为 .NET Framework 4、Silverlight 4 和 5 以及 Windows Phone 7.5 和 8 安装了 NuGet Package Async。
Version 1.0.16
我使用的是 Microsoft .NET 4.0,但由于 Web 托管包限制,我无法升级。(可悲!)
我的测试代码:(我正在使用 Linq to SQL Query 代替 Thread.Sleep)
public class Search
{
public async Task<List<Result>> GetResults(string SearchString)
{
await System.Threading.Tasks.Task.Factory.StartNew(() => Thread.Sleep(1000));
}
}
我的错误:
Cannot await 'System.Threading.Tasks.Task'
http://blogs.msdn.com/b/bclteam/p/asynctargetingpackkb.aspx谈到了错误,但这并不是真正的答案,因为我没有使用 VB,而且我已经在做解决方案描述的事情了。
[编辑] 我收到警告:
Warning 4 The primary reference "Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" could not be resolved because it has an indirect dependency on the framework assembly "System.Runtime, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" or retarget your application to a framework version which contains "System.Runtime, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
谢谢你的帮助。