You can't run in the background for an arbitrary time on Windows Phone. You can only run periodically (once every 30 minutes for 25s max execution time). And even then you're not guaranteed to run at all if:
- you previously crashed twice.
- the user turned your service off.
- battery saver is on. ...
See https://stackoverflow.com/a/13520869/694641 for more details of what is possible when your app is not in the foreground.