Introducing Windows Services
page 2 of 5
by Uday Denduluri
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 27743/ 85

ServiceBase Class

The base class for all the windows services is ServiceBase class. ServiceBase class has methods like OnStart, OnStop, OnPause and OnContinue which can be overridden by the derived classes. Let us see the ServiceBase class in detail and understand it before we create a windows service. When the service starts the OnStart method of the service runs. The Service Control manager is responsible for running the Service. All the events, like OnStart, OnStop, etc. are accessed by the Service control Manager. It is to be understood that this is not similar to normal executable file execution. The executable initially calls the derived class constructor of ServiceBase. After this the OnStart method takes on. It is to be understood that all the resources or objects that are needed to be cleared off in the Onstop event should be created in Onstart event and not the constructor.

The following are the methods or events of ServiceBase class. All these events can be overridden.

1.    OnStart – This method is fired when the service is started by the Service Control Manager. This method is used to specify the processing that occurs when a Start command is received.

2.    OnStop – This method is called when the service is stopped by the Service Control Manager. This is typically used to specify the processing that occurs when a Stop command is received by the Service Control Manager.

3.    OnPause – This method is called when the service is paused and typically contains the processing to pause the service.

4.    OnContinue – This method is called when the service is resumed after being paused. This method typically contains the necessary processing so as to enable a service to return to normal functioning after the same was paused earlier.

5.    OnShutdown – This method is called when the system is being shutdown and contains the necessary processing indicative of what should happen prior to the system shutting down.

6.    OnPowerEvent – This method is used to specify the necessary processing that should take place when the power status changes.

7.    OnCustomCommand – This method is used to specify a custom command, i.e., any command other than those discussed above.


View Entire Article

User Comments

Title: good   
Name: junaid.iqbal
Date: 2011-07-02 4:57:04 AM
Comment:
very good start
Title: Good   
Name: Ashok
Date: 2008-09-30 2:10:22 PM
Comment:
very good to start with.
Title: Suggestion   
Name: Everson
Date: 2008-06-13 8:49:11 AM
Comment:
Post here a draw of tipical windows service and then explain the theory about it.
Title: Well   
Name: Nitin Tiwari
Date: 2008-01-23 8:26:18 AM
Comment:
this is good for starting..
H T
Title: good article   
Name: good article
Date: 2007-10-04 2:56:56 AM
Comment:
Nice aricle
Title: depsre articol   
Name: OMU
Date: 2007-07-02 6:58:51 AM
Comment:
a good quick introduction to Widows Services

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2019 ASPAlliance.com  |  Page Processed at 2019-08-18 9:43:08 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search