我发现使用TimeTrigger是Windows 10(UWP)上预定后台任务的方式.但是看起来我们需要给出的最小数量是15分钟.只是想知道,警报和提醒如何适用于Windows 10,即使我们计划在接下来的1分钟内运行它.
我正在寻找一个应该在特定时间内触发任务的解决方案,其中包括不到15分钟.
任何人都可以对此有所了解吗?
闹钟和时钟应用程序使用计划的 Toast 通知而不是后台任务。
以下是在 10 秒内安排一次 Toast 的示例代码。
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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2225 次 |
| 最近记录: |