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

本文关键字:前台 应用程序 之间 任务 通信 Phone7 后台 Windows | 更新日期: 2023-09-27 18:33:59

我是Windows Phone 7的新手。

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

我有一个后台服务,并连接到 asmx 服务。 当我在ASMX上更新我的详细信息时,需要在手机上显示Toast消息,但我无法做到这一点,请帮助我

这是我的后台服务代码

          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.UpdateUserLocation1CompleteEventArgs e( {

        ShellToast toast = new ShellToast();

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

    } 

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

若要在应用程序和后台代理之间进行通信,应使用互斥体。

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

编辑:从OnInvoke中删除NotifyComplete(;并将其放入obj_UpdateUserLocation1Completed