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?
The Alarm & Clock application was using Scheduled Toast Notification rather than background task.
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);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With