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?

+3


source to share


2 answers


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.

+3


source


DispatcherTimer

- way. Please note, if you want your application to run in the background, you must declare this in your application manifest or use background agents.



+2


source







All Articles