我正在創建另一個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();
}
}
}
任何人都可以看到這個問題?
在此先感謝!
貝克斯
你能看到「Service Started」條目嗎? –