locked
Windows Service RRS feed

  • Question

  • User-1419011324 posted

    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

    Wednesday, March 3, 2010 1:33 PM

Answers

  • User-1878433365 posted

    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

    http://msdn.microsoft.com/en-us/library/3wf385ab.aspx 

     

    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 CanStop and CanPauseAndContinue properties.

    • 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 ServiceController class.

    <!--src=[../icons/alert_note.gif]-->3wf385ab.alert_note(en-us,VS.90).gifNote:

    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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 4, 2010 9:07 AM
  • User-319574463 posted

    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: http://social.msdn.microsoft.com/Forums/en-US/windowsgeneraldevelopmentissues/threads

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 11, 2010 8:05 AM

All replies

  • User-1878433365 posted

    Hello!

    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 it.

     

    Wednesday, March 3, 2010 2:01 PM
  • User-1419011324 posted

    Can you give me some URL where can I get more Information or example source code !!!

    Wednesday, March 3, 2010 2:29 PM
  • User-1878433365 posted

    Hello again,

    Here's an article entitled "Creating a Windows Service in C#" by pravin jayakumar:

    http://www.c-sharpcorner.com/UploadFile/pravinjr/106122008002100AM/1.aspx

     

    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 :-)

    Wednesday, March 3, 2010 3:08 PM
  • User-1419011324 posted

    Actually Article you send me for making new windows service  but I am looking for monitoring the existing service.

    Wednesday, March 3, 2010 3:31 PM
  • User-1878433365 posted

    I see.

    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.

    Wednesday, March 3, 2010 4:10 PM
  • User-574293449 posted

    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

    }

    Thursday, March 4, 2010 12:21 AM
  • User-1878433365 posted

    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

    http://msdn.microsoft.com/en-us/library/3wf385ab.aspx 

     

    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 CanStop and CanPauseAndContinue properties.

    • 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 ServiceController class.

    <!--src=[../icons/alert_note.gif]-->3wf385ab.alert_note(en-us,VS.90).gifNote:

    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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 4, 2010 9:07 AM
  • User-319574463 posted

    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: http://social.msdn.microsoft.com/Forums/en-US/windowsgeneraldevelopmentissues/threads

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 11, 2010 8:05 AM