System.Threading timer problem for beginner (Windo
I'm trying to do a windows service for the first time, and I would like it to send an e-mail with a specific interval. The problem is that it sends all the e-mails when I turn the service off, I would like it to send e-mails when it is running.
I get no errors in my code and would think the problem lies in the code below. Can anyone help me or suggest a better solution?
I am testing it on my computer with XP Professional and using the virtual SMTP on IIS, but it is going to be installed on a 2003 Server later. Does this make any difference?
public partial class mailTimer : ServiceBase{
private mailJob job;
private Timer stateTimer;
private TimerCallback timerDelegate;
public mailTimer(){
ServiceName = "Mail Service";
CanStop = true;
CanPauseAndContinue = false;
AutoLog = true;
}
protected override void OnStart(string[] args){
job = new mailJob();
timerDelegate = new TimerCallback(job.doSomething);
stateTimer = new Timer(timerDelegate, null, 30000, 30000);
}
protected override void OnStop(){
stateTimer.Dispose();
}
}
Thanks for any help!
|