c# - Timer doesn't restart after first interval -


I am trying to get a function to work in every X second and I want to do that for System I am using timers.

The first time when the function calls, instead of continuing to the next end, the decision ends. In any way, instead of simply using a loop? It seems that this timer will be misused.

My code is such:

  timer timer 1 = new timer (); Timer1.Elapsed + = New ElapsedEventHandler (some functions); Timer 1 Interval = 1000; // timer 1 in milliseconds Start ();    

Keep in mind that timer object can be garbage collected together done. Thus, you need to keep reference as long as you need it in the context of the timer. Otherwise the garbage collector will collect your timer and release unmanaged resources along with it and thus disable the timer.


Comments