【问题标题】:Debugging of WinRT's background networkingWinRT后台网络调试
【发布时间】:2012-08-03 08:48:34
【问题描述】:

我做了一个项目,而不是使用 tcp 套接字连接(自己的封闭协议),添加了与网络触发 API 的后台连接,如 here 所述(从第 17 页开始) - StreamSocket 控制通道注册块和 IBackgroundTask 类,每次套接字接收到东西时都应该触发它。

已经尝试了所有在后台任务中调试代码,没有用:

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

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

【问题讨论】:

    标签: c# debugging sockets background windows-runtime


    【解决方案1】:

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

    更新:

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

    1. 将后台项目添加到主项目的引用中(右键单击解决方案浏览器中的引用节点)。
    2. 检查主项目清单是否包含正确的声明(带控制通道的后台任务、带有完整包的正确后台入口点名称、$targetnametoken$.exe 作为可执行文件)
    3. 从 #1 引出的一点是:您计划在后台使用的所有实体都应放入解决方案中的单独项目中。该项目随后被主项目和后台项目引用。
    4. 注意在注册 ControlChannelTrigger 之前要调用 BackgroundExecutionManager.RequestAccessAsync()
    5. 我在示例项目的一个小评论中发现了一个关键点:
                // 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 线程(尤其是等待的东西) - 它们在应用程序运行之前不会运行,并且会等待。

    【讨论】:

    • 您能否详细说明如何“检查参考项目的可访问性”?因为我现在也有同样的问题。
    猜你喜欢
    • 2011-10-15
    • 1970-01-01
    • 2021-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多