this blog contains information for .net and sql stuffs. You can find various tips and tricks to overcome problem you may be facing in ...

Wednesday, May 12, 2010

Windows Service (Part-1)

Windows service are application that don’t have any visual element or visual effect, they run in back ground. Windows service run under particular user session as long as we have configured it.

Windows operating system it self provides many services we are familiar with IIS, telnet, Security Center services. We don’t use all services provided by operating system, sometime we require to have some application that run automatically and do work independently without interruption from user interaction. Application starts as we start our computer and run as long as computer don’t shutdown.

In such type of situation we can build up windows service application and host on our computer where we want to have automatic run and stop functionality.

Before we start to talk about how to develop windows service, we check how is it different from other application types?

We can’t run or debug windows service from visual studio development environment so there is no use of F5 and F11 in case of windows service project.

We have to create installer to run windows service, unlike other project we don’t have dll or exe files and can use easily. We need to install windows service by installing to a particular computer.

The main method of your windows service project must have run command, which loads service to service control manager on appropriate computer.

Unlike other application, you would not able to show message box when application crash, or something happened, it will run on background, you will not get any information once service start as after it fully controlled by operating system.

Windows services run on their own security context, we should take care of user account and security problem.

Creation of Windows service project

àChoose windows service template for windows project type.

àwrite your code on OnStart and OnStop procedures, we can override other methods too.

Once windows service started, we can’t have any control on it, we don’t get any thing, in that situation we can create timer object and start timer once windows service start. After that we can write event for timer time elapsed. In such a way we do useful work by using windows services.

No comments: