我正在尝试在我的Windows应用商店应用中设置Timer.
public void Start_timer()
{
Windows.UI.Xaml.DispatcherTimer timer = new DispatcherTimer();
timer.Tick += new Windows.UI.Xaml.EventHandler(timer_Tick);
timer.Interval = new TimeSpan(00, 1, 1);
bool enabled = timer.IsEnabled; // Enable the timer
timer.Start(); // Start the timer
}
Run Code Online (Sandbox Code Playgroud)
在按钮上单击我调用上面的方法来设置此计时器.但是当设置了Tickhand的Eventhandler时,我得到错误"尝试读取或写入受保护的内存.这通常表明其他内存已损坏."
我们是否需要在Windows应用商店应用中以不同方式处理定时器?
下面的方法在调用set Toast时执行,但是在时间弹出后不显示任何Toast.Windows 8 Metro应用程序Toast通知是否需要更多设置
int scheduledToastCounter = 1;
public void Set_Future_Toast()
{
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
XmlNodeList stringElements = toastXml.GetElementsByTagName("text");
stringElements.Item(0).AppendChild(toastXml.CreateTextNode("Scheduled Toast"));
DateTimeOffset displayTime = DateTimeOffset.UtcNow.AddSeconds(3);
ScheduledToastNotification scheduledToast = new ScheduledToastNotification(toastXml, displayTime);
scheduledToast.Id = "Future_" + this.scheduledToastCounter++;
ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier();
notifier.AddToSchedule(scheduledToast);
int scheduledToastCount = notifier.GetScheduledToastNotifications().Count;
}
}
Run Code Online (Sandbox Code Playgroud)