network-programminguwpwindows-10win-universal-appstream-socket-client

UWP StreamSocket When backgrounded do I lose the ability to send data?


UWP StreamSocket

I was wondering, when I socket.EnableTransferOwnership and then On_Suspended call socket.TransferOwnership(socketId); do I lose the ability to send data?

I am writing a UWP application that streams data, and I was hoping in the background my StreamSocket would still be able to send data out.

Thanks, Jacob


Solution

  • When your app gets suspended you won't be able to send out data anymore. Two options for you:

    1) you handle the data sending in a background task (which can run even if your app is suspended or terminated)
    2) you create an extended execution session (which will prevent your app from getting suspended in the first place)

    Links with more information:
    Background tasks overview: https://learn.microsoft.com/en-us/windows/uwp/launch-resume/support-your-app-with-background-tasks

    Extended execution overview: https://learn.microsoft.com/en-us/windows/uwp/launch-resume/run-minimized-with-extended-execution

    Run in the background indefinitely: https://learn.microsoft.com/en-us/windows/uwp/launch-resume/run-in-the-background-indefinetly