VS2012、C#、XAML、Windows Phone7 应用程序(刚从 Win7/VS2010 迁移而来)。
我刚刚将我的 WP7 应用程序迁移到 Win8/VS2012。 (我提到这一点以防下面的问题可能表明我可能指向了一个不正确的 DLL。)应用程序迁移得很好。我正在添加一些我在 VS2012 中原型(prototype)化的额外异步处理,并且被 VS 标记为以下错误:
var _Token = await Task.Run(() => (Token)_Serializer.ReadObject(_Response.GetResponseStream()));
VS 说“System.Threading.Tasks.Task 不包含‘运行’的定义。”我的 WP7 应用程序中 System.Threading.Tasks 的引用指向此位置:\packages\Microsoft.Bcl.1.0.16-rc\lib\sl4-windowsphone71\System.Threading.Tasks.dll
我通过 NuGet 添加了 Microsoft.Bcl.1.0.16-rc完成迁移到VS2012。这是不正确的吗?以前我使用的是 AsyncCtpLibrary_Phone 并被告知获取 Microsoft.Bcl.Async 将解决构建错误,例如:
The type 'System.Threading.Tasks.Task' exists in both AsyncCtpLibrary_Phone.dll' >and 'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\WindowsPhone\v8.0\mscorlib.dll. After adding the Microsoft.Bcl.Async the wp7 app built correctly and ran.
只有在尝试删除我在 VS2012 中原型(prototype)化的新异步代码之后,才出现 Task.Run 问题。
app.config 包含以下条目:
<dependentAssembly bcl:name="System.Threading.Tasks">
<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.5.11.0" newVersion="1.5.11.0" />
</dependentAssembly>
我需要安装其他软件包吗?
提前致谢,
保罗
最佳答案
在 Microsoft.Bcl.Async 中,就像在 Async CTP 中一样,Run
方法在 TaskEx
键入而不是 Task
.
关于windows-phone-7 - 异步等待 task.run - 未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15724051/