简体   繁体   English

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

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM