Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a dispatchertimer in WPF and I am finding it very frustrating because when I Start() it, it does not count as a tick. At the moment it's functionality is like this:

Start() [interval]
[tick]
[interval]
[tick]
...
How can I make it so the Start() counts as a tick and it starts immediately and make it work like this?:
Start() [tick]
[interval]
[tick]
Otherwise I have to duplicate what happens in the tick event before starting the timer which is not very efficient as I just want the timer to start immediately.
Posted
Updated 30-Nov-13 7:37am
v3
Comments
CHill60 30-Nov-13 15:00pm    
You could create a derived timer object and over ride the Start method to include a call to base.OnTick
Sergey Alexandrovich Kryukov 1-Dec-13 0:44am    
Don't you think it's even easier than that? Please see my answer.
—SA

I suggest not to break your head over the insignificant problem. Of course, never duplicate anything, ever. Create a separate method to be called from the tick handler and also call it at start. It would be a perfectly clean approach.

—SA
 
Share this answer
 
All I did was just call the tick event after starting the timer. I know its probably not the best way but it worked for what I needed.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900