且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在后台运行我的 Windows Phone 应用程序?

更新时间:2022-01-21 22:47:40

您的应用无法真正"在后台运行.它可以将某些任务交给操作系统,例如发送文件、播放音乐等.即使您的应用程序不再运行,操作系统也会继续执行这些任务.但是当用户离开您的应用时,它基本上会停止运行.

Your app cannot "really" run in the background. It can hand certain tasks to the operating system, like sending a file, playing music etc. These tasks will be continued by the OS even when your application is not running anymore. But when the user navigates away from your app it basically stops running.

使用 后台代理.PeriodicTask 让您的应用程序每 30 分钟运行一次约 15 秒.

What comes closest to running in the background can IMO be achieved using background agents. The PeriodicTask lets your application run for about 15 seconds about every 30 minutes.

很长一段时间(芒果之前)WP7在后台运行"意味着在锁屏下运行.这个有可能.但同样,当用户离开您的应用程序时,它会停止运行.

For quite some time (pre-Mango) "running in the background" for WP7 meant running under the lock screen. This is possible. But again, when the user navigates away from your application it stops running.

如果您需要在应用程序结束时与您的服务器通信,如果不需要很长时间,您可以这样做.如果我没记错的话,你有 大约 10 秒时间,当您的应用程序被停用时.如果您超过此限制,操作系统将终止您的应用.

If you need to talk to your server when the application ends you could do so if it doesn't take long. If I am not mistaken you have about 10 seconds time when your application is deactivated. If you exceed this limit the OS will kill your app.