Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在ThreadPoolTimer启动Windows应用商店C#后更改perion_C#_Timer_Windows Store Apps_Windows Store - Fatal编程技术网

在ThreadPoolTimer启动Windows应用商店C#后更改perion

在ThreadPoolTimer启动Windows应用商店C#后更改perion,c#,timer,windows-store-apps,windows-store,C#,Timer,Windows Store Apps,Windows Store,我尝试开发一个Windows应用商店应用程序。 我在MainPage.xaml.cs中有以下代码: public MainPage() { this.InitializeComponent(); int period = (int)20; ThreadPoolTimer timer = ThreadPoolTimer.CreatePeriodicTimer( (source) =

我尝试开发一个Windows应用商店应用程序。 我在MainPage.xaml.cs中有以下代码:

public MainPage()
        {
            this.InitializeComponent();
            int period = (int)20;
            ThreadPoolTimer timer = ThreadPoolTimer.CreatePeriodicTimer(
               (source) =>
               {
                   ToastTemplateType toastTemplate = ToastTemplateType.ToastText01;
                   XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);

                   XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
                   toastTextElements[0].AppendChild(toastXml.CreateTextNode("Push Noifications"));
                   IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
                   ((XmlElement)toastNode).SetAttribute("duration", "long");
                   ((XmlElement)toastNode).SetAttribute("launch", "{\"type\":\"toast\",\"param1\":\"hello\",\"param2\":\"world\"}");
                   ToastNotification toast = new ToastNotification(toastXml);
                   ToastNotificationManager.CreateToastNotifier().Show(toast);

               }, TimeSpan.FromSeconds(period));
        }
启动计时器后如何更改周期值

例如:

最初,我希望每20秒显示一次toast通知。 经过一些设置后,用户希望每X秒显示一次toast通知


感谢

对于桌面,底层winapi函数支持这一点,但WinRT api中没有公开。因此,除了取消现有函数并创建另一个函数之外,您可以做的事情不多了。我尝试创建两个相同的函数。在第一个函数中,周期是静态的。在另一个函数中,周期是动态的。这个解决方案的问题很大,因为它创建了新的线程,然后我无法更改线程中的控件。我想我们应该用其他方法同时完成这两件事。我认为解决办法是派遣员。谢谢你,汉斯