// Code to execute when the application is launching (eg, from Start)
        // This code will not execute when the application is reactivated
        private void Application_Launching(object sender, LaunchingEventArgs e)
        {
            TileRefreshNeeded = true;

            InitializeComponents();
            RefreshTilesPinState();

            PushHandler = new PushHandler(Resources["PushStatus"] as Status, Components, Dispatcher);
            PushHandler.EstablishConnections();
        }
        // Code to execute when the application is activated (brought to foreground)
        // This code will not execute when the application is first launched
        private void Application_Activated(object sender, ActivatedEventArgs e)
        {
            if (!e.IsApplicationInstancePreserved)
            {
                // The application was tombstoned, so restore its state
                foreach (var keyValue in PhoneApplicationService.Current.State)
                {
                    Components[keyValue.Key] = keyValue.Value as ComponentInformation;
                }

                // Reconnect to the MSPN
                PushHandler = new PushHandler(Resources["PushStatus"] as
             Status, Components, Dispatcher);
                PushHandler.EstablishConnections();
            }
            else if (!PushHandler.ConnectionEstablished)
            {
                // Connection was not fully established before fast app
                // switching occurred
                PushHandler.EstablishConnections();
            }

            RefreshTilesPinState();
        }