0

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. But call of UserTrackAsync is not executing.

J. Steen
  • 15,470
  • 15
  • 56
  • 63
Nodir
  • 359
  • 1
  • 3
  • 17
  • If I'd have to hazard a **guess**, I'd say it's because `point` is null, or an utterly swallowed exception is thrown. Have you tried debugging, at all? – J. Steen Jul 24 '13 at 10:50
  • Of course. There is no exceptions. – Nodir Jul 24 '13 at 11:01
  • Then `point` is null? – J. Steen Jul 24 '13 at 11:02
  • No, `point` is specified by user location. I have add this: `client.UserTrackCompleted += (sender, args) => { var res = args.Result.Retval; };` Break point is never access by debuger. – Nodir Jul 24 '13 at 11:05
  • If `point` is not null and there are no exceptions, then `client.UserTrackAsync` is executing. You're just not getting the expected result, which you haven't detailed. Consider tracing on your soap service. – J. Steen Jul 24 '13 at 11:07
  • The very strange situation. `OnMethodComplete` is not occured. When web service called by another console program all works – Nodir Jul 24 '13 at 11:14

1 Answers1

1

Your client.UserTrackAsync is an async call. The problem is that NotifyComplete(); is executed before client.UserTrackAsync has a chance to finish.

You need to call it in the UserTrackCompleted handler (and delete it from the original place):

client.UserTrackCompleted += (sender, args) => 
{ 
    var res = args.Result.Retval; 
    NotifyComplete();
};
Igor Kulman
  • 16,211
  • 10
  • 57
  • 118