다른 Windows 서비스를 만들고 타이머가 똑딱 거리지 않아서 그 이유를 알 수 없습니다! 이전 서비스에서 사용하던 system.timers.timer를 사용하고 있는데 작동하지 않습니다. 나는 그것에 붙이려고했지만 아무 것도하지 않는 것 같습니다.System.Timers.Timer timer1_Elapsed가 실행되지 않습니다! 도움!
내 코드 :
namespace ExpiryNotifier
{
public partial class ExpiryNotifier : ServiceBase
{
public ExpiryNotifier()
{
InitializeComponent();
if (!System.Diagnostics.EventLog.SourceExists("ExpiryNotifier"))
{
System.Diagnostics.EventLog.CreateEventSource("ExpiryNotifier", "ExpiryNotifier");
}
eventLog1.Source = "ExpiryNotifier";
eventLog1.Log = "ExpiryNotifier";
}
private Timer timer1 = new Timer();
protected override void OnStart(string[] args)
{
eventLog1.WriteEntry("Service Started");
timer1.Elapsed += timer1_Elapsed;
timer1.Interval = 10000;
timer1.Enabled = true;
}
protected override void OnStop()
{
eventLog1.WriteEntry("Service Stopped");
timer1.Enabled = false;
}
private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
eventLog1.WriteEntry("timer tick");
timer1.Stop();
EmailerService.EmailerService service = new EmailerService.EmailerService();
DataSet expiringQualifications = service.GetDetailsOfExpiringQualifications();
if(expiringQualifications.Tables[0].Rows.Count>0)
{
foreach(DataRow rw in expiringQualifications.Tables[0].Rows)
{
if (!string.IsNullOrEmpty(rw["EmailAddress"].ToString()))
{
if (rw["QualAwardDescription"] != null)
{
service.SendQualExpiryEmail(rw["EmailAddress"].ToString(), rw["firstName"].ToString(),
rw["QualAwardDescription"].ToString());
}
}
}
}
timer1.Start();
}
}
}
사람이 문제를 볼 수 있을까요?
미리 감사드립니다.
벡스
"서비스 시작"항목을 볼 수 있습니까? –