Using WinRT on the Desktop with LockScreen API

让人想犯罪 __ 提交于 2019-12-25 07:47:09

问题


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 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.



来源:https://stackoverflow.com/questions/21817780/using-winrt-on-the-desktop-with-lockscreen-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!