计划任务代理wp7 soap客户端不工作

本文关键字:客户端 工作 soap wp7 任务 代理 计划 | 更新日期: 2023-09-27 18:24:35

我有这个:

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的调用没有执行。

计划任务代理wp7 soap客户端不工作

您的client.UserTrackAsync是一个异步调用。问题是在client.UserTrackAsync有机会完成之前执行NotifyComplete();

您需要在UserTrackCompleted处理程序中调用它(并从原始位置删除它):

client.UserTrackCompleted += (sender, args) => 
{ 
    var res = args.Result.Retval; 
    NotifyComplete();
};