Edge Extension本机消息传递:处理UWP消息的大小限制 [英] Edge Extension Native Messaging: Dealing with UWP message size limit

查看:88
本文介绍了Edge Extension本机消息传递:处理UWP消息的大小限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Edge开发一个扩展,我需要从UWP向该扩展发送1MB以上的数据.

I am developing an extension for Edge where I need to send more than 1MB of data to the extension from UWP.

我已将数据分割成小于1MB的数据,并尝试多次发送回复,如下所示:

I have chunked the data to be less than 1MB and tried to send reply multiple times something like below

private async void OnAppServiceRequestReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args) {
  AppServiceDeferral messageDeferral = args.GetDeferral();

  // This is to be replaced with enumerator
   for (int i = 0; i < number_of_chunks; i++) {
      // construct reply identifying the chunk number and termination
       await args.Request.SendResponseAsync(reply);
   }
   messageDeferral.Complete();

}

在上述循环中发送第二个响应时,应用程序服务被取消.似乎只有在有相应的请求时才可以发送响应.有人可以确认吗?

The app service is cancelled when sending the second response in the above loop. It seems like a response can be sent only if there is a corresponding request. Can someone confirm this?

UWP中是否有任何其他机制可以在没有请求的情况下异步发送数据?

Are there any alternative mechanisms in UWP to send the data asynchronously without a request?

我可以想到的另一种选择是将分块逻辑移到后台,感觉不对.

Another option I can think of is to have the chunking logic moved to the background and it doesn't feel right.

FWIW,Chrome& Firefox没有这种限制,我可以异步将消息发送到stdout.

FWIW, Chrome & Firefox doesn't have such limitation and I am able to send messages to stdout asynchronously.

更新#1:彼得,第二个sendReply恐怕遇到相同的错误在意外时间调用了方法".我尝试了以下方法,希望这就是您的意思.

Update#1: Peter, I am afraid I get the same error "A method was called at an unexpected time" for the second sendReply. I tried the following and hope this is what you meant.

private async void OnAppServiceRequestReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args) {

  // This is to be replaced with enumerator
   for (int i = 0; i < number_of_chunks; i++) {
      // construct reply identifying the chunk number and termination
      AppServiceDeferral messageDeferral = args.GetDeferral();
      await args.Request.SendResponseAsync(reply);
      messageDeferral.Complete();
   }
}

推荐答案

您需要呼叫args.GetDeferral(),以避免在第一次挂起呼叫(await)时断开连接.然后,一旦完成工作,您就需要在延期中致电Complete().

You need to call args.GetDeferral() in order to avoid having your connection torn down at the first suspension call (await). Then you need to call Complete() on the deferral once your work is done.

这篇关于Edge Extension本机消息传递:处理UWP消息的大小限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆