How to raise an event at any given time
I am trying to raise an event at a specific time in a windows store app. I've done this in desktop apps countless times now, and I've used it System.Threading.Timer
in the past and it worked well, but this class is not available for Windows Store apps.
I looked through the documentation and found a class called DispatchTimer
and although I feel like I'm behind it, correct me if I'm wrong, but the docs are missing. But luckily, it's pretty easy to use.
So I tried it DispatchTimer
, but after using it I'm not even sure if this is what I should be using.
How can I watch for a specific time and raise an event when that time (in the Windows Store app)? And do you know of any resources that do this in the metro app?
source to share
Use DispatcherTimer
like this:
var timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(10) };
timer.Tick += OnTimerTick;
timer.Start();
private void OnTimerTick(object sender, object args)
{
// Do something with pickup here...
}
This will create a timer every 10 seconds.
source to share