Web​Socket​Keep​Alive Web​Socket​Keep​Alive Web​Socket​Keep​Alive Class


Provides the ability to send a WebSocket protocol keep-alive on a connected WebSocket.

public : sealed class WebSocketKeepAlive : IBackgroundTaskpublic sealed class WebSocketKeepAlive : IBackgroundTaskPublic NotInheritable Class WebSocketKeepAlive Implements IBackgroundTask
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)


The WebSocketKeepAlive class is used in conjunction with the ControlChannelTrigger class and related interfaces to enable real-time network status and triggers for the StreamWebSocket and MessageWebSocket classes. Control channel triggers are used by long-running network apps to minimize network and system resource usage. Network triggers allow an app to drop to a low-power mode for periods of time while still keeping established network connections intact but in a low-power state. An app can set a keep-alive trigger used by the system for when the app should wake up and send a WebSocket keep-alive packet.

A Windows Store app is normally suspended when it is no longer in the foreground. There are some exceptions where an app should not be suspended (actively printing, accessing an audio stream, and transferring files in the background, for example). The ControlChannelTrigger class allows a network app that has established a WebSocket connection to notify the system that the network connection should be kept operational and that the system should wake up the suspended app when network data is received for the app or to send a WebSocket keep-alive packet.

WebSocketKeepAlive is used as the TaskEntryPoint for a keep-alive in ControlChannelTrigger. A developer will need to write code to handle receiving data.

For more information about suspending and waking up an app, How to set background connectivity options.

For more information on the WebSocket keep-alive control frames, see the WebSocket Protocol.


WebSocketKeepAlive() WebSocketKeepAlive() WebSocketKeepAlive()

Creates a new WebSocketKeepAlive object.

public : WebSocketKeepAlive()public WebSocketKeepAlive()Public Sub New()


Run(IBackgroundTaskInstance) Run(IBackgroundTaskInstance) Run(IBackgroundTaskInstance)

Sends a WebSocket protocol keep-alive on a connected WebSocket.

public : void Run(IBackgroundTaskInstance taskInstance)public void Run(IBackgroundTaskInstance taskInstance)Public Function Run(taskInstance As IBackgroundTaskInstance) As void
IBackgroundTaskInstance IBackgroundTaskInstance IBackgroundTaskInstance

Specific instance of a background task.

See Also