我有这个:
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事件。但是UserTrackAsync的调用没有执行。
答案 0 :(得分:1)
您的client.UserTrackAsync
是异步通话。问题是NotifyComplete();
在client.UserTrackAsync
有机会完成之前执行。
您需要在UserTrackCompleted
处理程序中调用它(并从原始位置删除它):
client.UserTrackCompleted += (sender, args) =>
{
var res = args.Result.Retval;
NotifyComplete();
};