Enumerate available mobile broadband accounts

Updated: August 27, 2013

Applies To: Windows 8, Windows 8.1

There are two methods that you can use to enumerate network accounts: polling or event-based.

  • Polling The mobile broadband app can poll for available network accounts by using the static MobileBroadbandAccountStatics.AvailableNetworkAccountIds method. This is ideal if the application simply needs a snapshot of the accounts and does not need to respond at run time to accounts that are being added or removed.

  • Event-based You can use the MobileBroadbandAccountWatcher class to enumerate and then monitor for changes to mobile broadband accounts. The event-based method is ideal when the application must respond to changes (that is, return to the account selection page when the currently selected account is removed). The procedure to use this class is as follows:

    1. Instantiate a MobileBroadbandAccountWatcher object.

    2. Add event handlers to the AccountAdded, AccountRemoved, and EnumerationCompleted events.

    3. Invoke Start() on the watcher.

    The AccountAdded event handlers are invoked for each existing network account. When all of the existing network accounts are enumerated, the EnumerationCompleted event is raised.

    Additional AccountAdded and AccountRemoved events are raised as account availability changes (that is, when mobile broadband hardware or the SIM is removed).

Account watcher objects automatically stop when the app is suspended by Windows, and restart when the app is resumed. This is done to preserve battery life because resuming a suspended app to process an event and then putting it back in the suspended state can result in significant disk activity. The Stopped event occurs when the watcher stops (this happens either right before or right after the app gets its Suspending event). When the app resumes, all watchers that were running before the app was suspended automatically restart, thereby triggering a series of AccountAdded events that are followed by an EnumerationCompleted event (the same way as if the Start method had been called). This enables the app to get up-to-date with anything significant that occurred during the time that it was suspended.

MobileBroadbandAccountWatcher objects are independent of each other. This means that you cannot depend on all watchers reporting the same set of events – as a group, they will report all events. However, any given watcher might not report any given event, because that event has been consumed by another watcher. Unless you have good reason, you should use only one account watcher object per app.

See Also