Is updating LiveTile on Application_Deactivated a good practice?
-
21-06-2021 - |
문제
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.
해결책
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.
다른 팁
I used to update the livetile in the Application_Deactivated, however this caused issues with resuming, so I removed that feature.
Someone else found the same issue and updates in a different area: http://www.japf.fr/2012/12/updating-the-live-tiles-when-the-exits-wp8-weirdness/