是否可以在WinForm中与AppServiceConnection和uwp进行通信?错误:不包含" GetAwaiter"的定义,这是我的代码: 谢谢!
这是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
答案 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。