如何使用“AppServiceConnection”在“WinForm”中进行通信

时间:2018-06-06 07:10:57

标签: c# winforms

如何使用“AppServiceConnection”在“WinForm”中进行通信

这是我的代码,但无法执行

AppServiceConnection appService = new AppServiceConnection();
        appService.AppServiceName = "com.yanscorp.appservicedemo.Values";
        appService.PackageFamilyName = "c97887ad-1f75-4b48-9e3b-21b89c061715_6evysfdvxt248";

        //if used "await" Error:"IAsyncOperation" does not contain the definition of "GetAwaiter".
        //var status = await appService.OpenAsync();

        //Remove "await"
        var status = appService.OpenAsync();

        //but run status.GetResults(),throw: invoking a method at an unexpected time
        if (status.GetResults() == AppServiceConnectionStatus.Success)
        {
            string d = "Failed to connect";
            return;
        }

        var message = new ValueSet();
        message.Add("Request", "GetCallCount");
        //if used "await" Error:"IAsyncOperation" does not contain the definition of "GetAwaiter".
        //AppServiceResponse response = await appService.SendMessageAsync(message);

        //Remove "await"
        var s = appService.SendMessageAsync(message);

        //but run status.GetResults(),throw: invoking a method at an unexpected time
        AppServiceResponse response = s.GetResults();
        string result = "";

        if (response.Status == AppServiceResponseStatus.Success)
        {
            result = response.Message["Response"] as string;
            textBlock.Text = result;
        }

请请帮帮我,谢谢

1 个答案:

答案 0 :(得分:0)

您尚未引用系统。将using System;放在代码顶部