Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

My dispatcher timer is not calling on timer_tick event. it's my code:

DispatcherTimer timer = new DispatcherTimer();
timer.Tick += timer_tick();
timer.Interval = new TimeSpan(0,0,0,10);
timer.Start();

timer_tick(object sender, EventArgs e)
{...}

Plz, help me!

share|improve this question

closed as too localized by SPDoctor May 31 '12 at 10:06

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Closed at request of OP –  SPDoctor May 31 '12 at 10:05

2 Answers 2

I'm found solution of my problem. PageLoad method exits prior to when the first DispatcherTimer event could ever occur.

As soon as Main finishes, the process will shut down, as there are no other foreground threads.

That being said, DispatcherTimer really only makes sense in a use case where you have a Dispatcher, such as a WPF or Silverlight application. Therefore, I'm should consider using the Timer class.

System.Timers.Timer _timer = new System.Timers.Timer();
_timer.Interval = 5000;
_timer.Elapsed  += _timer_Tick;
_timer.Enabled = true;
share|improve this answer

Your eventhandler binding is incorrect, correct is:

timer.Tick += new EventHandler(timer_tick);

It is best to hit TAB after typing += and Visual Studio will magically create the event handler code for you.

share|improve this answer
    
Jussi Palo, I know about TAB :) simply i'm using Resharper, and it's suggested more universal subscribe to events. But with timer.Tick += new EventHandler(timer_tick); my dispatcher also timer is not calling on timer_tick event. I don't know why :((( –  Damir Beylkhanov Feb 16 '12 at 4:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.