C# 如何在windows phone中使用定期代理

C# 如何在windows phone中使用定期代理,c#,xml,xaml,windows-phone-7,windows-phone-8,C#,Xml,Xaml,Windows Phone 7,Windows Phone 8,我在我的应用程序中使用了一个定期代理,我必须在用户设置的给定间隔内以30分钟的频率显示引号。在下面的调用方法中,我读取xml文件以获取开始时间、结束时间和频率的值,在另一个尝试捕获中获取引号的xml文件。 我想在30分钟后调用invoke方法来显示引号 protected override void OnInvoke(ScheduledTask task) { TimeSpan minute; TimeSpan hour; try

我在我的应用程序中使用了一个定期代理,我必须在用户设置的给定间隔内以30分钟的频率显示引号。在下面的调用方法中,我读取xml文件以获取开始时间、结束时间和频率的值,在另一个尝试捕获中获取引号的xml文件。 我想在30分钟后调用invoke方法来显示引号

protected override void OnInvoke(ScheduledTask task)
    {
        TimeSpan minute;
        TimeSpan hour;

        try
        {

            using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream stream = myIsolatedStorage.OpenFile("Reminder.xml", FileMode.Open))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(List<ReminderModel>));
                    List<ReminderModel> data = (List<ReminderModel>)serializer.Deserialize(stream);

                    foreach (var item in data)
                    {
                        //if (item.StartTime <=item.EndTime)
                        if (item.StartTime < DateTime.Now && item.EndTime >= DateTime.Now)
                        {
                            if (item.Frequency.TimeOfDay.Hours == 0)
                            {
                                minute = new TimeSpan(item.Frequency.TimeOfDay.);
                                // minute = new TimeSpan(item.Frequency.Minute);

                                item.StartTime.AddMinutes(item.Frequency.TimeOfDay.Minutes);
                            }
                            else
                            {
                                 hour = new TimeSpan(item.Frequency.Hour);
                                item.StartTime.AddHours(item.Frequency.TimeOfDay.Hours);
                            }

                        }
                        else
                        {
                            MessageBox.Show("The Periodic agent is stop");
                        }



                    }

                }
            }

        }

        catch (Exception)
        {
        }


        try
        {
            using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream stream = myIsolatedStorage.OpenFile("Notification.xml", FileMode.Open))
                {

                    using (StreamReader reader = new StreamReader(stream))
                    {
                        var Data = reader.ReadToEnd();
                        var value = Data.Replace("\r\n", "").Remove(0, 74).Split('<');
                        this.QuoteRemoveList.Clear();
                        foreach (var item in value)
                        {
                            if (item.StartsWith("QuoteElement"))
                            {

                                this.QuoteRemoveList.Add(item.Remove(0, 13));
                            }


                        }
                    }

                }


            }
        }

        catch
        { }


        {

            Random rd = new Random();


            string toastMessage = QuoteRemoveList[rd.Next(0, 99)];


            ShellToast toast = new ShellToast();
            toast.Title = "Quotes";
            toast.Content = toastMessage;
            toast.Show();
            NotifyComplete();

            // If debugging is enabled, launch the agent again in one minute.
            //#if DEBUG_AGENT
            // ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(60));
            //#endif


                if (this.Agent.hour>0)
                {
                    ScheduledActionService.LaunchForTest(periodicTaskName, TimeSpan.FromHours(personalViewModel.Frequency.TimeOfDay.Hours));
                }
                else if (this.Agent.minute > 0)
                {
                    ScheduledActionService.LaunchForTest(periodicTaskName, TimeSpan.FromMinutes(personalViewModel.Frequency.Minute));
                }
            }




        }

    }
protected override void OnInvoke(ScheduledTask任务)
{
时间跨度-分钟;
时间跨度小时;
尝试
{
使用(IsolatedStorage File myIsolatedStorage=IsolatedStorage File.GetUserStoreForApplication())
{
使用(IsolatedStorageFileStream=myIsolatedStorage.OpenFile(“remement.xml”,FileMode.Open))
{
XmlSerializer serializer=新的XmlSerializer(typeof(List));
列表数据=(列表)序列化程序。反序列化(流);
foreach(数据中的var项)
{
//if(item.StartTime=DateTime.Now)
{
如果(item.Frequency.TimeOfDay.Hours==0)
{
分钟=新的时间跨度(项目、频率、时间);
//分钟=新的时间跨度(项目频率分钟);
item.StartTime.AddMinutes(item.Frequency.TimeOfDay.Minutes);
}
其他的
{
小时=新的时间跨度(项目频率小时);
item.StartTime.AddHours(item.Frequency.TimeOfDay.Hours);
}
}
其他的
{
MessageBox.Show(“周期代理停止”);
}
}
}
}
}
捕获(例外)
{
}
尝试
{
使用(IsolatedStorage File myIsolatedStorage=IsolatedStorage File.GetUserStoreForApplication())
{
使用(IsolatedStorageFileStream=myIsolatedStorage.OpenFile(“Notification.xml”,FileMode.Open))
{
使用(StreamReader=新StreamReader(stream))
{
var Data=reader.ReadToEnd();
var value=Data.Replace(“\r\n”,”).Remove(0,74)。Split(“从这里开始())您可以了解
后台代理如何在windows phone中工作的详细信息,也可以从这里开始()获得相关指南

如何为Windows Phone 8实现后台代理。在i实现之前,请参阅第一个链接中的指导原则和说明。

先生,我之前已经阅读了这些文章,然后开始使用定期代理。我的问题是,在阅读first try catch block中的xml文件后,我得到了开始时间、结束时间和频率,我需要frtimespan中的频率。我尝试转换它,但它不起作用。我只需要timespan中的频率,以便进一步工作。周期代理通常运行25秒。还有其他限制可能导致代理提前终止。电池节电模式是用户可以在设备上启用的选项,以指示电池寿命应该优先。如果启用此模式,即使间隔已过,周期代理也可能无法运行。因此,由urself设置时间间隔或频率非常棘手,它可能会运行,也可能不会运行。