如何在后台运行我的 Windows Phone 应用程序? [英] How can I run my Windows Phone application in background?

查看:35
本文介绍了如何在后台运行我的 Windows Phone 应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道 Windows Phone 应用程序是否可以在后台运行.我研究过 http://msdn.microsoft.com/en-us/library/ff431744(v=vs.92).aspx.在那里我找到了有关后台文件传输、代理和警报的信息.但是手机可以在后​​台播放音乐.我的问题是:我想在后台运行 Windows Phone 应用程序,当我按下返回键时,它也能够运行该应用程序.

I want to know whether a Windows Phone application can run in the background or not. I have studied http://msdn.microsoft.com/en-us/library/ff431744(v=vs.92).aspx. There I found information on Background File Transfers, Agents, and Alarms. But the phone can play music in the background. My question is: I want to run windows phone application in the background, when I press the back key also it is able to run that application.

我的应用程序连接到服务器,如果用户按下返回键,是否可以在后台模式下更新服务器端的信息?

My application is connected to a server, if a user presses the back key, can it update information on the server side in background mode?

推荐答案

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

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.

这篇关于如何在后台运行我的 Windows Phone 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆