How to persist a websocket connection using ControlChannelTrigger in the background?
Hello, I followed https://learn.microsoft.com/en-us/windows/uwp/networking/network-communications-in-the-background#controlchanneltrigger-with-websockets and create an out-of-process background task using ControlChannelTrigger with MessageWebSocket.
Everything works fine in the foreground, however, if I close the app window, the websocket connection will be killed and no longer receive any message.
I re-opened my app but found registered BackgroundTasks didn't exist any more and I had to register them again.
How can I persist a websocket connection using ControlChannelTrigger in the background?
Hi, Can you provide a minimum runnable demo? This will help us debug and resolve your issue. In addition, maybe this official example provided by Microsoft will help you, it shows how to create a
StreamSocketthat can still be active outside the application life cycle. Although it is different from
WebSocket, the general process is the same and can be used as a reference.
Hello, may you please provide further information to help us solve the problem?
I can provide a minimal repro, but I cannot find a suitable websocket server for now...
You can refer to the example of
StreamSocketI provided to create another Server project to run locally.
Here's my repro project:
Hi, I tested your project and there are two main issues. The first point is that the full name of
Windows.Networking.Sockets.WebSocketKeepAlive, not a class created by yourself. Regarding the inability to register the
BackgroundTask, it seems to be caused by the
Trigger, and there may be an exception during the creation of the channel. However, there is a known issue here. If you replace
Windows.Networking.Sockets.WebSocketKeepAlive, the project cannot be generated correctly. For details, see this issue. Our engineer teams is currently working on this issue. If there something news, I will post it here.
Thanks for your reply. I'll try again once the issue got fixed.
Sure, I will follow up on the content and if there have new progress I will post
Hi, I've verified that the issue in https://github.com/MicrosoftDocs/windows-uwp/issues/2205 has been fixed in Windows 10 SDK 19624.
However, I still cannot persist a WebSocket connection using ControlChannelTrigger in the background. Every time when I close the app, the WebSocket connection will break unexpectedly.
Here's my new repro: https://1drv.ms/u/s!ApWNk8G_rszRgcZ_0wEDZ_LbWF8w9A?e=N5WhXO
Sign in to comment