Using WinRT on the Desktop with LockScreen API

2019-09-17 20:17发布

I'm writing a toy desktop app that interacts the LockScreen API, which is part of WinRT and uses async/await. After following the instructions here, I've enabled support for WinRT and added the following references:

System.Runtime.dll
System.Runtime.WindowsRuntime.dll
System.Runtime.InteropServices.WindowsRuntime.dll

However I still get this error while building:

'System.Runtime.CompilerServices.TaskAwaiter' does not contain a definition for 'IsCompleted'

The error is associated with the await line of my code. What else am I missing?

Edit: Here's the code in question and the full list of references for the project.

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);
    }
}

References

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

1条回答
可以哭但决不认输i
2楼-- · 2019-09-17 21:06

I have found that setting target platform to x64 on 64-bit PC could resolve the issue. Developers on this MSDN forum thread were solving a similar problem as you are having, although for Windows 8 Consumer Preview, so it is hard to tell, if the solution is still valid.

查看更多
登录 后发表回答