Nodir
Nodir

Reputation: 369

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

Upvotes: 0

Views: 250

Answers (1)

Igor Kulman
Igor Kulman

Reputation: 16359

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();
};

Upvotes: 1

Related Questions