public void OnTimer(object sender, ElapsedEventArgs args) { // TODO: Insert monitoring activities here. //eventLog1.WriteEntry("Monitoring the System", EventLogEntryType.Information, eventId++); DateTime now = DateTime.Now; if (now.Hour > 6 && now.Hour < 20) { try { var r = new MailUtilityCon(); r.ControlloCarenzeMagazzino(conNection, ""); } catch (Exception) { } } }
protected override void OnStart(string[] args) { try { var r = new MailUtilityCon(); r.ControlloCarenzeMagazzino(conNection, ""); } catch (Exception) { } Timer timer = new Timer(); timer.Interval = Convert.ToDouble(360000); // 360000 seconds = 1 Ora timer.Elapsed += new ElapsedEventHandler(this.OnTimer); timer.Start(); //eventLog1.WriteEntry("In OnStart."); }