windows-phone-7comexceptionlive-tile

Is updating LiveTile on Application_Deactivated a good practice?


I have not used Background Agents for updating LiveTiles. I update the tile on exiting of the app and on Application_Deactivated.

private void Application_Deactivated(object sender, DeactivatedEventArgs e)
    {
        CycleManager pCycMan = CycleManager.Instance;
        pCycMan.WriteToIsolatedStorage();

        ResourceManager resMan = new ResourceManager("xxx.AppResources", Assembly.GetExecutingAssembly());

        ShellTile PrimaryTile = ShellTile.ActiveTiles.First();
        StandardTileData tile = new StandardTileData();

        try
        {
            if (PrimaryTile != null)
            {
                tile.BackTitle = resMan.GetString("liveTileTitle");
                tile.BackBackgroundImage = new Uri("/Background.png", UriKind.Relative);


                if (pCycMan.GetStartDate() == pCycMan.GetDefaultDate())
                {
                    tile.Title = resMan.GetString("liveTileNotTrackingStatus");
                }
                else
                {
                    tile.Title = m_liveTileText;
                }

                PrimaryTile.Update(tile);
            }
        }
        catch(Exception)
        {
        }
    }

Is is a good practice to do so? The app is published and I have received a StackTrace with a COMException. It shows that the exception is raised on execution of Microsoft.Phone.Shell.ShellTile.Update after the XXX.App.Application_Deactivated

Does anyone know of this exception or faced such situations? It would be really helpful if someone could guide me on this.


Solution

  • When the Application_Deactivated event is raised, you have 10 seconds to finish your task. After that, your application will be terminated.

    So maybe the crash happened because your code took more than 10 seconds to complete.