Service Question - Sending Email on successful startup.

  • Thread starter Thread starter Smithers
  • Start date Start date
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!
 
Further testing shows that the email messages sent during the OnStart event
procedure are *eventually* sent - after a delay of 1-2 minutes.

-S
 
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.
 
Back
Top