I am trying to set Timer in my Windows Store App.
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
}
On button click I call above method to set this Timer. But when Eventhandler for Tick is set, I get error "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
Do we need to handle Timers differently in Windows Store apps?
The solution is to move the Timer out of the method e.g
private DispatcherTimer timer = new DispatcherTimer();
and set it up in the ctor
public TheClass()
{
timer.Tick += timer_Tick;
timer.Interval = new TimeSpan(00, 1, 1);
timer.Start();
}
Hard to tell what is the reason without the full code, but it could be the behavior of the timer_Tick.
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