gpt4 book ai didi

c# - WinRT后台网络调试

转载 作者:行者123 更新时间:2023-12-03 12:05:59 26 4
gpt4 key购买 nike

我做了一个项目,而不是使用 tcp 套接字连接(自己的封闭协议(protocol)),添加了使用网络触发 API 的后台连接,如 here 所述(从第 17 页开始) - StreamSocket 控制 channel 注册 block 和 IBackgroundTask 类,应在每次套接字接收到某些内容时触发。

已尝试一切在后台任务中调试代码,但没有用:

  • 用手势关闭可见应用
  • 锁屏
  • 尝试加载其他一些繁重的应用程序,以使 Windows 暂停我的应用程序

  • 所有这些都没有帮助我在套接字消息期间使后台任务运行(和调试)。我究竟做错了什么?我是否必须获得单独的可暂停设备(如 WinRT 平板电脑)才能使其正常工作?

    最佳答案

    默认情况下,引用的项目不会添加到主项目中。这并不像看起来那么明显,这就是为什么我花了将近一周的时间来找出这个。所以线索是:检查引用项目的可访问性 .

    更新:

    正如我在开发过程中发现的那样,还有更多的事情需要处理。其中一些并不像他们需要的那样清楚。这是我所做的列表:

  • 将后台项目添加到主项目的引用中(右键单击解决方案浏览器中的引用节点)。
  • 检查主项目 list 是否包含正确的声明(带控制 channel 的后台任务,带有完整包的正确后台入口点名称,$targetnametoken$.exe 作为可执行文件)
  • 从 #1 引出的一件事:您计划在后台使用的所有实体都应该放在解决方案中的单独项目中。然后这个项目被主项目和后台项目引用。
  • 请注意在注册 ControlChannelTrigger
  • 之前要调用 BackgroundExecutionManager.RequestAccessAsync()
  • 我在示例项目的一个小评论中发现了一个关键点:
  •             // IMPORTANT: When using winRT based transports such as StreamWebSocket with the ControlChannelTrigger, 
    // we have to use the raw async pattern for handling reads instead of the await model.
    // Using the raw async pattern allows Windows to synchronize the PushNotification task's
    // IBackgroundTask::Run method with the return of the receive completion callback.
    // The Run method is invoked after the completion callback returns. This ensures that the app has
    // received the data/errors before the Run method is invoked.
    // It is important to note that the app has to post another read before it returns control from the completion callback.
    // It is also important to note that the DataReader is not directly used with the
    // StreamWebSocket transport since that breaks the synchronization described above.
    // It is not supported to use DataReader's LoadAsync method directly on top of the transport. Instead,
    // the IBuffer returned by the transport's ReadAsync method can be later passed to DataReader::FromBuffer()
    // for further processing.

    更多信息在这里 - http://code.msdn.microsoft.com/windowsapps/ControlChannelTrigger-91f6bed8/sourcecode?fileId=57961&pathId=2085431229

    如果你做的一切都正确,后台任务的调试就很简单了。只需设置断点并继续,不要管主项目正在运行或暂停。

    ps - 如果项目被暂停,请注意调用 UI 线程(尤其是等待的东西) - 它们在应用程序运行之前不会运行,并且会等待。

    关于c# - WinRT后台网络调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11792361/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com