Tech
Forums
Jobs
Books
Events
Videos
Conference
Annual Conference
Bcrypt
Ai Conference
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
1
Answer
System.Threading timer problem for beginner (Windows service, sending e-mails)
Ask a question
Ask a question
Upload Source Code:
Select only zip and rar file.
Erik Petersen
18y
2.7k
1
Reply
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!
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
Synchronizing two different objects
Opening Microsoft Office files in a multithreaded environment