Service Question - Sending Email on successful startup.

S

Smithers

I have a service that will periodically send email messages to system
adminstrators. I would like for this service to send a email notification
whenever the service is started and when it is stopped. I placed attempted
to do that from the OnStart event procedure... but any messages sent during
the OnStart procedure are not sent. But when the service is stopped, the
email messages from both the OnStart and OnStop event procedure are sent.

How can I send email messages from a service when it starts successfully?
Apparently the OnStart event procedure is not the place to do it. I looked
at the ServiceBase class and didn't see any other events or methods that
would apparently do what I need.

Thanks!
 
S

Smithers

Further testing shows that the email messages sent during the OnStart event
procedure are *eventually* sent - after a delay of 1-2 minutes.

-S
 
W

Willy Denoyette [MVP]

Smithers said:
I have a service that will periodically send email messages to system
adminstrators. I would like for this service to send a email notification
whenever the service is started and when it is stopped. I placed attempted
to do that from the OnStart event procedure... but any messages sent during
the OnStart procedure are not sent. But when the service is stopped, the
email messages from both the OnStart and OnStop event procedure are sent.

How can I send email messages from a service when it starts successfully?
Apparently the OnStart event procedure is not the place to do it. I looked
at the ServiceBase class and didn't see any other events or methods that
would apparently do what I need.

Thanks!


The OnStart method should only be used to perform basic service
initialization stuff, when OnStart doesn't return within 30 seconds after
the SCM posted the Start command, the SCM will flag the service as "failed
to start" and kill the service process. So, sending a mail from within
OnStart makes no sense, at this point, the Service didn't yet start and you
have no guarantee it ever will.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top