I also need this functionality. That is, my Windows C # service should check email every 10 minutes. I shared some logic to make the code more efficient, as follows:
private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { _timer.Stop(); try { EventLog.WriteEntry(Program.EventLogName, "Checking emails " + _count++); } catch (Exception ex) { EventLog.WriteEntry(Program.EventLogName, "This is my error " + ex.Message); } _timer.Start(); }
The timer_elapsed method will actually be called every 10 minutes, starting with the first _timer.start (), which you, by the way, will miss. I did not check _lastRun and startAt. I don't think we need it
swdev source share