Click here to Skip to main content
15,883,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using a wp7 application, and i would like to make a timer in which every 10 seconds a method is called in the background. i am trying to google it but i cannot find any examples which are good for me.

any help please?
Posted
Comments
koolprasad2003 7-Oct-11 3:50am    
set timer1.Interval at 10000 (10000 Milisecond = 10sec.)

1 solution

With Windows Phone 7 you should use the DispatcherTimer found in the System.Windows.Threading namespace. Then you just add a method to it's Tick EventHandler


C#
System.Windows.Threading.DispatcherTimer dt = new System.Windows.Threading.DispatcherTimer();
        dt.Tick += new EventHandler(Tick);
        dt.Start();

        void Tick(object sender, EventArgs e)
        {
                // Do work here.
        }


hope this helps
 
Share this answer
 
Comments
Mehdi Gholam 7-Oct-11 3:48am    
my 5!
adnama 7-Oct-11 3:48am    
Thank you for your reply. how would one set it as to 10 seconds?
Wayne Gaylard 7-Oct-11 3:56am    
You just add a TimeSpan to the Interval property of the DispatcherTimer

dt.Interval = new TimeSpan(0,0,10);
adnama 7-Oct-11 4:02am    
oh thank you very much thats what i needed. it worked perfectly. the thing is that when i close the form it continues doing it, how do i stop the timer when the wp7 form is closed and another thing is being done?
Wayne Gaylard 7-Oct-11 4:11am    
You will need to unsubscibe to the Tick event and dispose of the timer in your form closing event.

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