Windows 10(UWP)中的TimeTrigger / Scheduler不到15分钟

时间:2015-10-02 02:33:47

标签: scheduler uwp

我发现使用TimeTrigger是Windows 10(UWP)上预定后台任务的方式。但是看起来我们需要给出的最小数量是15分钟。只是想知道,警报和提醒如何适用于Windows 10,即使我们计划在接下来的1分钟内运行它。

我正在寻找能够在特定时间内触发任务的解决方案,其中包括不到15分钟。

任何人都可以对此有所了解吗?

1 个答案:

答案 0 :(得分:4)

警报&时钟应用程序使用预定的Toast通知而不是后台任务。

enter image description here

以下是在10秒内安排祝酒的示例代码。

namespace UWPApp
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        private Random random = new Random((int)DateTime.Now.Ticks);

        const string TOAST = @"
<toast>
  <visual>
    <binding template=""ToastGeneric"">
      <text>Sample</text>
      <text>This is a simple toast notification example</text>
      <image placement = ""AppLogoOverride"" src=""oneAlarm.png"" />
    </binding>
  </visual>
  <actions>
    <action content = ""check"" arguments=""check"" imageUri=""check.png"" />
    <action content = ""cancel"" arguments=""cancel""/>
  </actions>
  <audio src =""ms-winsoundevent:Notification.Reminder""/>
</toast>";


        public MainPage()
        {
            this.InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var when = DateTime.Now.AddSeconds(10);

            var offset = new DateTimeOffset(when);

            Windows.Data.Xml.Dom.XmlDocument xml = new Windows.Data.Xml.Dom.XmlDocument();

            xml.LoadXml(TOAST);

            ScheduledToastNotification toast = new ScheduledToastNotification(xml, offset);

            toast.Id = random.Next(1, 100000000).ToString();

            ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast);
        }
    }
}