xaml - How can I set a timer in C#? -
in c#, want set timer when entering page, have ten second countdown begin.
if user not complete operation within ten seconds, timer triggered, suggesting "game over".
if user has completed operation within ten seconds, timer device canceled.
how can this?
use dispatchertimer
class. tick
event handler should have code says game over.
dispatchertimer dispatchertimer = new system.windows.threading.dispatchertimer(); dispatchertimer.tick += dispatchertimer_tick; dispatchertimer.interval = new timespan(0,0,10); dispatchertimer.start(); private void dispatchertimer_tick(object sender, eventargs e) { ((dispatchertimer)sender).stop(); //your code here }
whenever user completed operations, can call dispatchertimer.stop();
. stop timer.
Comments
Post a Comment