【发布时间】:2014-03-16 01:58:06
【问题描述】:
我正在编写一个与LockScreen API 交互的玩具桌面应用程序,它是 WinRT 的一部分并使用async/await。按照here 的说明操作后,我启用了对 WinRT 的支持并添加了以下参考:
System.Runtime.dll
System.Runtime.WindowsRuntime.dll
System.Runtime.InteropServices.WindowsRuntime.dll
但是我在构建时仍然收到此错误:
'System.Runtime.CompilerServices.TaskAwaiter' does not contain a definition for 'IsCompleted'
该错误与我的代码的await 行有关。我还缺少什么?
编辑:这是有问题的代码和项目参考的完整列表。
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Runtime.InteropServices;
using Windows.System.UserProfile;
using System.IO;
using Windows.Storage.Streams;
public class Program : Form
{
[STAThread]
static void Main()
{
...
}
public Program()
{
string wallpaper = ...
...
SetLockScreenImage(wallpaper);
}
private async void SetLockScreenImage(string path)
{
InMemoryRandomAccessStream ras = new InMemoryRandomAccessStream();
...
await LockScreen.SetImageStreamAsync(ras);
}
}
参考文献
Microsoft.CSharp
System
System.Core
System.Data
System.Data.DataSetExtension
System.Deployment
System.Drawing
System.Runtime
System.Runtime.InteropServices.WindowsRuntime
System.Runtime.WindowsRuntime
System.Windows.Forms
System.Xml
System.Xml.Linq
Windows
【问题讨论】:
-
你能分享代码并添加完整的参考列表吗?
-
您使用的是哪个版本的 .NET?您是否尝试过添加 Microsoft.Bcl.Async NuGet 包,它在某些缺失的平台上添加了对 async/await 的完全支持? nuget.org/packages/Microsoft.Bcl.Async
标签: c# .net wpf windows-runtime async-await