In my wp7.5 app, i have a block where i need to show a stopclock (say 30,29,28...1,0). I tried various implementations to achieve this using DispatchTimer and Timer classes, but none of them solved my problem.
Approach 1: Here is the snippet i used for DispatchTimer,
DispatcherTimer dt = new DispatcherTimer();
dt.Interval = new TimeSpan(0, 0, 1); // 1 second
dt.Tick += new EventHandler(dt_Tick);
for(int count=0;count<30;count++)
dt.Start();
void dt_Tick(object sender, EventArgs e)
{
// my UI control update here
}
in my Tick event implementation i am updating a UI control with time counter. I read some questions here on the same topic, where dispatcher tick never fires in some scenarios because of UI thread. It happened same to me, tick event never fired.
Approach 2: I tried using System.Threading.Timer class,
Timer timer = new Timer(TimerProc);
for(int count=0;count<30;count++)
timer.Change(1000, 0);
void TimerProc(object sender)
{
// my UI control update here
}
None my approaches worked. I might have asking a repeated question, can anyone point me where I am doing incorrectly in the code?