1
I am developing a windows service to run every 10 minutes, it inserts some values in the database, but I noticed that the routine only runs once.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Teste.BLL.Servidor;
using Teste.DTO.Servidor;
using Teste.Referencia.Email;
namespace Teste.AtualizaArmazenamentoServidores
{
public partial class Service1 : ServiceBase
{
Timer timer;
EventLog log = new EventLog();
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
System.Diagnostics.Debugger.Launch(); //adicionado para conseguir deggugar no Visual Studio
timer = new Timer(new TimerCallback(timer_Tick), null, 15000, TimeSpan.FromSeconds(40).Milliseconds); //coloquei 40 segundos para testar
}
protected override void OnStop()
{
}
public void timer_Tick(object sender)
{
ExecutarTarefa();
}
public void ExecutarTarefa()
{
try
{
new ServidorBLL().SalvaDadosServidoresBanco();
}
catch (Exception ex)
{
SendEmail("Atualiza Servico", ex);
}
}
}
}
Routine works, data is updated in the right database, but in debug, the method is not called again after the first execution.
I thank anyone who can help.