我有一个相当简单的问题。
我们使用BackgroundAgents( 周期剂 )来执行一些需要WiFi(Internet)连接的后台任务,以执行HttpWebRequest。正如第二个参考中提到的,HttpWebRequest是受支持的,但问题是,如果Windows被锁定或空闲超过1分钟,WiFi就会被禁用。
我有两个重要的问题,根据我读过的和尝试过的,直到知道:
谢谢。
样本代码:
protected override void OnInvoke(ScheduledTask task)
{
ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(120));
MakeHttpRequest("test");
}
private void MakeHttpRequest(string position)
{
if (position != null)
{
var request = (HttpWebRequest)WebRequest.Create(
new Uri("http://mydomain.com/Testing/Details/"+position));
request.BeginGetResponse(r =>
{
var httpRequest = (HttpWebRequest)r.AsyncState;
var httpResponse = (HttpWebResponse)httpRequest.EndGetResponse(r);
using (var reader = new StreamReader(httpResponse.GetResponseStream()))
{
var response = reader.ReadToEnd();
Deployment.Current.Dispatcher.BeginInvoke(new Action(() =>
{
}));
}
}, request);
}
this.NotifyComplete();
}PS:请记住,当我使用USB电缆连接到计算机时,当我运行这个代码时,一切都很好。这就是为什么我认为后台工作人员没有唤醒电话+ WiFi来执行tha HttpWebRequest的问题。
发布于 2012-04-20 21:41:02
我每天使用手机的经验是,除非手机被插上电源和充电,否则Windows在锁定后不会重新启用wifi。它还允许已经启动的数据传输在禁用wifi之前完成。
但是,即使手机试图定期重新连接,一些wifi提供商也会在每次用户重新连接时重定向到身份验证页面,而Windows phone不处理这种情况。
实际上,在用户使用手机时,无法保证您有可用的数据服务,因此处理该问题应该是应用程序代码的正常路径的一部分。
https://stackoverflow.com/questions/10251373
复制相似问题