UWP StreamSocket在后台运行时,我是否无法发送数据?

时间:2019-02-14 02:16:13

标签: networking uwp windows-10 win-universal-app stream-socket-client

UWP StreamSocket

我想知道,什么时候我先socket.EnableTransferOwnership然后On_Suspended调用socket.TransferOwnership(socketId);我会失去发送数据的能力吗?

我正在编写一个流数据的UWP应用程序,我希望在后台我的StreamSocket仍然能够发送数据。

谢谢, 雅各布

1 个答案:

答案 0 :(得分:0)

应用暂停后,您将无法再发送数据。您有两个选择:

1)您在后台任务中处理数据发送(即使您的应用被暂停或终止,该任务也可以运行)
2)您创建了一个扩展执行会话(这将防止您的应用程序一开始就被暂停)

具有更多信息的链接:
背景任务概述: https://docs.microsoft.com/en-us/windows/uwp/launch-resume/support-your-app-with-background-tasks

扩展的执行概述: https://docs.microsoft.com/en-us/windows/uwp/launch-resume/run-minimized-with-extended-execution

无限期在后台运行: https://docs.microsoft.com/en-us/windows/uwp/launch-resume/run-in-the-background-indefinetly