[英]Scheduled task agent wp7 soap client does not work
I have this: 我有这个:
public class ScheduledAgent : ScheduledTaskAgent
{
...
protected override void OnInvoke(ScheduledTask task)
{
var userSettings = Utils.LoadSettings();
try
{
var client = new CheckinServiceSoapClient();
var token = WsApiCaller.Token;
var point = ... // User Location;
if (point != null)
{
client.UserTrackAsync(token, userSettings.UserId,
point.Latitude, point.Longitude,
point.Position.Location.HorizontalAccuracy,
point.Position.Location.Altitude,
point.Position.Location.Speed,
point.Position.Location.VerticalAccuracy,
point.Position.Location.Course,
"BACKGROUND_AGENT");
}
}
catch
{
}
NotifyComplete();
}
}
OnInvoke event occurs. 发生OnInvoke事件。 But call of UserTrackAsync is not executing.
但是UserTrackAsync的调用未执行。
Your client.UserTrackAsync
is an async call. 您的
client.UserTrackAsync
是异步调用。 The problem is that NotifyComplete();
问题是
NotifyComplete();
is executed before client.UserTrackAsync
has a chance to finish. 在
client.UserTrackAsync
有机会完成之前执行。
You need to call it in the UserTrackCompleted
handler (and delete it from the original place): 您需要在
UserTrackCompleted
处理程序中调用它(并将其从原始位置删除):
client.UserTrackCompleted += (sender, args) =>
{
var res = args.Result.Retval;
NotifyComplete();
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.