Last post Mar 11, 2010 08:05 AM by TATWORTH
Mar 03, 2010 01:33 PM|milindsaraswala|LINK
I was looking for some help on windows service. Actually my need is when particular windows service stop or fail I need to send alert email or by Text Message. So is there any way to check windows service
Mar 03, 2010 02:01 PM|aderegil|LINK
A windows service has some events like OnStop() and OnPause() where you can put code to notify you by email.
But asking a failing service to notify when it fails is not something reliable. If it fails, it may not be able to send you an email.
Another approach is to have the service to report its health every few seconds/minutes. And then have a second, different application, that will monitor those reports. If it finds a time gap then something is not ok with the windows service and it can report
Mar 03, 2010 02:29 PM|milindsaraswala|LINK
Can you give me some URL where can I get more Information or example source code !!!
Mar 03, 2010 03:08 PM|aderegil|LINK
Here's an article entitled "Creating a Windows Service in C#" by pravin jayakumar:
It's for Visual Studio 2005 but it is almost the same for Visual Studio 2008.
Go ahead and try it by yourself. You can even download the source code.
I have a couple of heavy use web services in operation these days so I know a thing or two so I may help you in the future :-)
Mar 03, 2010 03:31 PM|milindsaraswala|LINK
Actually Article you send me for making new windows service but I am looking for monitoring the existing service.
Mar 03, 2010 04:10 PM|aderegil|LINK
I do not have an article for that.
What I do is to code a function in my windows service to go to the database and log the last access time. That's all that is needed on the windows service.
To monitor, you can have a second windows service that is reading the lattest access time and that will send emails in case it finds a gap in time.
That is what I mean.
Mar 04, 2010 12:21 AM|akhilrajau|LINK
hi friend you can check the service status from your page and send the email alert.
a small example:
ServiceController sc = new ServiceController("servicename");
if(sc.Status == "Stopped")
//mail alert code here
Mar 04, 2010 09:07 AM|aderegil|LINK
Wow that is nice! I was not aware of that :-)
There is documentation on MSDN about all this at
Introduction to Communicating with Existing Services
You can use the ServiceController component to connect to and control the behavior of existing services. When you
create an instance of the ServiceController component, you set it to interact with a specific Windows service. You
can then use the component instance to start, stop, and otherwise manipulate the service. For example, you might create a
ServiceController component and use it with a
Timer component to start and stop a service based on a timed interval.
You can do several useful things with the ServiceController component. For example:
You can start and stop the service to which you are connected, pause it, or perform any of the other administrative actions to which the service is capable of responding. For more information, see
How to: Perform Administrative Tasks on Services.
You can query various properties of the service with which the component interacts and retrieve the property values. For example, you might determine whether the service can be stopped, paused, and continued by retrieving the value of the
You can return a list of the services that exist on a particular computer.
You can specify a custom command to call on your service. For more information on custom commands, see MSDN Online.
The ServiceController component actually passes its requests for actions to the Services Control Manager, rather
than to the service itself. The Services Control Manager then stops, starts, or pauses the service or performs other actions as specified. After the
ServiceController has passed the request on to the Services Control Manager, it returns; it does not wait for the Services
Control Manager to pass the request on to the service. Because of this, you should handle exceptions within the service class itself rather than in the
In general, you should not add a ServiceController component to a Windows Service application if your intent is for
that component to manipulate the service contained in the same project. Code within the project that creates a service cannot be used to control the service; it must be controlled from another context.
Mar 11, 2010 08:05 AM|TATWORTH|LINK
In the CommonData solution at
http://commondata.codeplex.com/, there is a sample Windows Service that maintains a heartbeat by updateing a specified row in the ParamDate table. It is then simple to write a monitor stored procedure that looks at the heartbeat records and if any of the
engtries are older than say heartbeat periods, flag an alarm.
For further help on Windows Services ask at: