计划任务代理wp7 soap客户端无法正常工作

时间:2013-07-24 10:47:22

标签: c# windows-phone-7 background-agents

我有这个:

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

1 个答案:

答案 0 :(得分:1)

您的client.UserTrackAsync是异步通话。问题是NotifyComplete();client.UserTrackAsync有机会完成之前执行。

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

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