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

TimeTrigger/Scheduler in Windows 10 (UWP) for less than 15 minutes

我发现使用 TimeTrigger 是 Windows 10 (UWP) 上预定后台任务的方式。然而,我们需要给出的最少时间似乎是 15 分钟。只是想知道 Windows 10 的闹钟和提醒是如何工作的,即使我们将其安排在接下来的 1 分钟 运行。

我正在寻找一种应在特定时间(包括少于 15 分钟)内触发任务的解决方案。

任何人都可以阐明这一点吗?

闹钟和时钟应用程序正在使用计划的 Toast 通知而不是后台任务。

这是在 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);
        }
    }
}