Guidelines and checklist for using network triggers (XAML)

[This article is for Windows 8.x and Windows Phone 8.x developers writing Windows Runtime apps. If you’re developing for Windows 10, see the latest documentation]

This topics describes best practices for using networking triggers and for background network notifications to support your Windows Store app that needs to be always connected.

  • Guidance using network triggers
  • Security Considerations
  • Related topics

Guidance using network triggers

Consider the following guidance when registering your ControlChannelTrigger:

  • Use ControlChannelTriggerId to differentiate between ControlChannelTrigger objects associated with transport connections to different destinations on the Internet. For example, a mail client could assign different channel IDs to the connections to different mail servers or mail boxes. The channel ID is a string specified while creating a control channel trigger object.
  • When the transport object is no longer required, apps are encouraged to call the appropriate IDisposable.Dispose method on the transport object to ensure deterministic release of the hardware resources. The StreamSocket, MessageWebSocket, and the StreamWebSocket objects support the IClosable interface. In JavaScript, this is projected as the Close method. For apps written using the .NET Framework 4.5 in C# and VB.NET, the Close method is exposed as the Dispose() method on the StreamSocket, MessageWebSocket, and the StreamWebSocket objects. For apps written in C++, the Close method will be called when using the delete keyword on the object.
  • When a ControlChannelTrigger object is no longer required, the Close method should be called to release resources. The ControlChannelTrigger object supports the IClosable interface. In JavaScript, this is projected as the Close method. For apps written using the .NET Framework 4.5 in C# and VB.NET, the Close method is exposed as the Dispose() method on the ControlChannelTrigger object. For apps written in C++, the Close method will be called when using the delete keyword on the object.

Security Considerations

The following articles provide guidance for writing secure C++ code.

Other resources

Adding support for networking

Background Networking

Lock screen overview

Staying connected in the background

Supporting your app with background tasks

Troubleshooting and debugging network connections

Reference

ControlChannelTrigger

HttpClient

HttpClientHandler

IXMLHTTPRequest2

MessageWebSocket

StreamSocket

StreamWebSocket

System.Net.Http

Windows.ApplicationModel.Background

Windows.Networking.Sockets

Samples

Background task sample

ControlChannelTrigger HttpClient sample

ControlChannelTrigger with IXMLHTTPRequest2 sample

ControlChannelTrigger TCP socket sample

ControlChannelTrigger StreamWebSocket sample

Lock screen apps sample