Windows Phone7中后台(周期性任务)和前台应用程序之间的通信?

时间:2012-05-14 03:35:58

标签: c# windows-phone-7 asmx

我是Windows Phone 7的新手。

我正在wp7中开发一个项目,在该项目中每60秒我需要将我的纬度经度详细信息发送到Web服务(asmx)。

我有后台服务,并连接到asmx服务。当我更新我的asmx细节时需要在手机上显示吐司信息,但我无法做到,请帮助我

这是我的后台服务代码

          protected override void OnInvoke(ScheduledTask task)
               {

        watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);
        watcher.Start();
        string useremail = task.Description.ToString();
        string latitude = watcher.Position.Location.Latitude.ToString();
        string longitude = watcher.Position.Location.Longitude.ToString();

        ServiceReference1.UpdateUserLocationSoapClient obj = new ServiceReference1.UpdateUserLocationSoapClient();
        obj.UpdateUserLocation1Completed += new EventHandler<ServiceReference1.UpdateUserLocation1CompletedEventArgs>(obj_UpdateUserLocation1Completed);
        obj.UpdateUserLocation1Async(useremail, latitude, longitude);   
        // If debugging is enabled, launch the agent again in one minute.
        #if DEBUG_AGENT
        ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(5));
        #endif

        // Call NotifyComplete to let the system know the agent is done working.
        NotifyComplete();
    }

private void obj_UpdateUserLocation1Completed(object sender,ServiceReference1.UpdateUserLocation1CompletedEventArgs e)         {

        ShellToast toast = new ShellToast();



        toast.Title = "kk";
        toast.Content = "ss" + e.Result.ToString();
        toast.Show();


    } 

1 个答案:

答案 0 :(得分:1)

要在您的应用程序和后台代理之间进行通信,您应该使用互斥锁。

示例:http://www.31a2ba2a-b718-11dc-8314-0800200c9a66.com/2011/11/this-is-continuation-of-this-post.html

编辑:删除NotifyComplete();来自OnInvoke并将其放入obj_UpdateUserLocation1Completed