Gracefully handle background task when app tombstones

限于喜欢 提交于 2019-12-12 03:19:30

问题


I'm using the async ctp and have a task that runs in the background. It works great but throws an exception when it's running and the app is tombstoned. The exception is related to the database context being null.

The docs say:

When an application is tombstoned, the underlying database connections are closed. To return to its previous state after tombstoning, an application needs to redo any queries it had performed before it was tombstoned.

I've tried using a cancellationtokesource but this doesn't seem to work as the connection is already closed. Any idea how to handle something like this?


回答1:


We also had a number of problems with this, but the general architecture of a mobile app tends to be service oriented so most people will not have to worry about database connections. Handling tombstoning is error prone in general - this area was one of the prolific bug generators in my project.

It is OK (not great) as a user experience to return to the start screen after waking up from tombstoning and not to the last screen. Otherwise you could cache the data you already have - using the IsolatedStorage and try to redo the screen.



来源:https://stackoverflow.com/questions/9401236/gracefully-handle-background-task-when-app-tombstones

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!