Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

scheduler

uwp

I figured out using TimeTrigger is the way for the scheduled background task on Windows 10 (UWP). However it looks like minimum number we need to give is 15 minutes. Just wondering, how the Alarm and reminders work for Windows 10 even we schedule it to run for next 1 minute.

I am looking for a solution that should trigger a task in a specific time which include less than 15 minutes.

Can any one shed some light on this?

like image 516
My Helper Avatar asked Oct 02 '15 02:10

My Helper


1 Answers

The Alarm & Clock application was using Scheduled Toast Notification rather than background task.

enter image description here

Here is the sample code to schedule a toast in 10 seconds.

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);
        }
    }
}
like image 124
Jeffrey Chen Avatar answered Oct 17 '22 22:10

Jeffrey Chen