How to Create a .NET Windows Service Easily
Window services are the applications which are controlled and managed by Service Control Manager and generally used in servers as they are long running applications. Other interesting thing to note here is that they do not have any user interface and also they don’t require any user for starting or executing them. In these article methodologies for creating .NET based Window Services will be discussed.
used method for creating .NET Windows Service is timer based approach.
Generally no user interaction is involved in these types of applications;
there is need of a timer whose task is to manage the invocation of a backstage
thread at regular intervals. For understanding this in more detail you
should know about the System.ServiceProcess.Service class and its methods.
This is the class which is extended by all the .NET based services and it has three methods which need to be overridden by the service. There are OnStart and OnStop methods which controls the starting and stopping of the service respectively. Also there is a method called Dispose which cleanup the resources which are no longer required. So in Timer approach first you should create a timer in the OnStart method and then can put your working function details under it. The working function has the code which needs to be executed at regular intervals, when the timer got activated.
There are two alternatives to this method. First is single thread approach in which a separate thread is created for the invocation of working function. Also the working function will work in an endless loop till the service is running. It is suspended when the service is stopped. In the second alternative which is multiple thread approach there are multiple worker threads. It can be viewed as an array of worker threads in the background for controlling the service.
With the help of .NET framework and the classes it provides, it has become quite easy to develop a window service. It was a tough task earlier as there was need to use system level procedures if you are creating a window service using C/C++. Also .NET allows creating as well as installing and controlling the window service.
Visual Studio .NET is a nice IDE for creating these applications as it eases the task with its visual drag and drop controls and built in templates. There is window service project available from the project templates which can be used as a foundation of our development.
Also timer is available as an object in the toolbox and it can be dragged to our project surface. So with the help of .NET framework, class libraries and the IDE, Visual Studio .NET you have got a comparatively simpler, easier and user friendly way of creating a window service.
to our mailing list and receive new articles
: We never rent, trade, or sell my email lists to
Visit .NET Programming Tutorial Homepage
| About Runtime Components of .NET Framework | About Session Management in a Web Based Enterprise Application | An introduction to Microsoft Mobile Internet Toolkit (MMIT) | How to Internationalize Your .NET Application | How to Create a Document Type Definition (DTD) | How to Create a .NET Windows Service Easily | Knowing the Difference Between Application Server and Web Server | Understanding Key Advantages of .NET Type System | Understanding Some Basic Language Related Features of C# |