【问题标题】:Communication between Background(periodic task) and foreground app in windows phone7?windows phone7中后台(定期任务)和前台应用程序之间的通信?
【发布时间】:2012-05-14 03:35:58
【问题描述】:

我是 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(对象发送者,ServiceReference1.UpdateUserLocation1CompletedEventArgs e) {

        ShellToast toast = new ShellToast();



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


    } 

【问题讨论】:

    标签: c# windows-phone-7 asmx


    【解决方案1】:

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

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

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

    【讨论】:

    • 是的,我知道,但我在后台服务中使用 asmx Web 服务(参见代码)。当后台服务触发它调用 asmx,当 asmx 完成时(私有 void obj_UpdateUserLocation1Completed)方法将调用。但是这个方法会发送一个 toasrt 通知(见代码)或将数据保存到本地数据库我们从 asmx 得到什么结果,但它没有运行,请帮助我
    • 移除 NotifyComplete();来自 OnInvoke 并将其放入 obj_UpdateUserLocation1Completed
    • julien,非常感谢,它现在解决了我的问题,我过去确实这样做过,但现在效果很好,非常感谢
    猜你喜欢
    • 1970-01-01
    • 2011-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多