【问题标题】:Using WinRT on the Desktop with LockScreen API通过 LockScreen API 在桌面上使用 WinRT
【发布时间】: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


【解决方案1】:

我发现在 64 位 PC 上将目标平台设置为 x64 可以解决此问题。 this MSDN forum thread 上的开发人员正在解决与您遇到的类似问题,尽管对于 Windows 8 Consumer Preview,因此很难判断该解决方案是否仍然有效。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-28
    • 1970-01-01
    • 1970-01-01
    • 2011-12-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多