是否可以在WinForm中与AppServiceConnection和uwp进行通信

时间:2018-06-06 02:51:03

标签: c# winforms uwp

是否可以在WinForm中与AppServiceConnection和uwp进行通信?错误:不包含" GetAwaiter"的定义,这是我的代码: enter image description here 谢谢!

这是WinForm中的代码:

private AppServiceConnection calculatorService;
    static Form1 mainForm;
    public Form1()
    {
        InitializeComponent();
    }

    private async void button1_Click(object sender, EventArgs e)
    {
        //Add the connection
        if (calculatorService == null)
        {
            calculatorService = new AppServiceConnection();
            calculatorService.AppServiceName = "com.yanscorp.appservicedemo.Values";
            calculatorService.PackageFamilyName = "c97887ad-1f75-4b48-9e3b-21b89c061715_6evysfdvxt248";

            var status = await calculatorService.OpenAsync();//A mistake here

            if (status != AppServiceConnectionStatus.Success)
            {
                string d = "Failed to connect";
                return;
            }
        }
var message = new ValueSet();
        message.Add("Request", "GetCallCount");
        AppServiceResponse response = await calculatorService.SendMessageAsync(message);//A mistake here
        string result = "";

        if (response.Status == AppServiceResponseStatus.Success)
        {
            result = response.Message["Response"] as string;
            // Get the data  that the service sent  to us.

                textBlock.Text = result;

        }
    }

错误: 错误CS4036“IAsyncOperation”不包含“GetAwaiter”的定义,并且找不到可接受类型为“IAsyncOperation”的第一个参数的扩展方法“GetAwaiter”(是否缺少针对“系统”的使用指令?)WindowsFormsApplication1

1 个答案:

答案 0 :(得分:0)

  

是否可以与WinService中的AppServiceConnection和uwp进行通信

是。您可以在WinForm中使用App服务。查看this article了解更多详情。

  

错误:不包含“GetAwaiter”的定义

您可以通过引用winmd文件和System.Runtime.WindowsRuntime.dll访问WinForm中的Windows 10 API。您好像已经引用了winmd,但是您可能忘记在System.Runtime.WindowsRuntime.dll目录中引用C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5

添加System.Runtime.WindowsRuntime.dll的引用将解决您的问题。详情请参阅Calling Windows 10 APIs From a Desktop Application