How to: Receive Push Notifications While an Application is in the Foreground for Windows Phone

[Note: This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

4/22/2010

While an application is running in the foreground, all push notifications are routed to the application.

Receiving Raw Notifications

Raw notifications are only delivered to the application when it is running in the foreground. If the application is not running in the foreground, the raw notification message is dropped.

The following code sample describes how to receive a raw notification.

void httpChannel_HttpNotificationReceived(object sender, HttpNotificationEventArgs e)
{
      if (e.Notification.Body != null)
      {
          System.IO.StreamReader reader = new System.IO.StreamReader(e.Notification.Body);
      }
}

Receiving Tile Notifications

Tile notifications are always delivered to the tile, regardless of if the application is running in the foreground. However, if the application is running in the foreground, the tile notification is also routed to the application.

The following code sample describes how to receive a tile notification.

void httpChannel_ShellEntryPointNotificationReceived(object sender, NotificationEventArgs e)
{
      if (e.Collection != null)
      {
          Dictionary<string, string> collection = (Dictionary<string, string>)e.Collection;

          System.Text.StringBuilder messageBuilder = new System.Text.StringBuilder();

          foreach (string elementName in collection.Keys)
          {
               ...
          }
      }
}

Receiving Toast Notifications

Toast notifications are only delivered to the device when the application is not running in the foreground. If the application is running in the foreground, the toast notification is instead routed to the application.

The following code sample describes how to receive a toast notification.

void httpChannel_ShellNotificationReceived(object sender, NotificationEventArgs e)
{
      if (e.Collection != null)
      {
          Dictionary<string, string> collection = (Dictionary<string, string>)e.Collection;

          System.Text.StringBuilder messageBuilder = new System.Text.StringBuilder();

          foreach (string elementName in collection.Keys)
          {
               ...
          }
      }
}

Show: