I have a problem that min timer event is not fired when it should be, I set it to an interval of 500ms, but as I can see in my logg, this doesn't work as intended. I want the code to excecute when wait 0.5 seconds then start executing again!
public void initilize_Rfid() { _timerComm = new System.Timers.Timer(500); _timerComm.Elapsed += CommTimerEvent; _timerComm.Enabled = true; } private void CommTimerEvent(object source, ElapsedEventArgs e) { try { _timerComm.Enabled = false; Logg("Inside CommTimerEvent " + _name); //TALKING TO A SERIALPORT AND DETERMENATING IF TO CONTINUE WITH THE TIMER if ((_continueTimer) { _timerComm.Enabled = true; Logg("Re-activating timer " + _name); } } catch (Exception ex) { Logg(ex.ToString()); } } I can see the text "Inisde ComTimerEvent TEST1", and then about 0.8 seconds later I get my "Re-activating timer TEST1". That is all just fine. But after this I get a up to 3 seconds delay until the timer fires again... Can I prevent this in some way?
System.Timers.Timerit has anAutoResetproperty. Set this to false and the timer will only run once. Then, in the timer method, start it again like you do. This way you don't need to stop/start the timer all the time.System.Timers.Timer. Are you sure that you're not doing anything else after starting the timer? Are you sure that you understood thatSystem.Timers.Timerevents run in a different thread than the UI thread (exceptions might slow things down)?