Thursday 2 January 2014

Windows Service development questions

1. What are Windows services?

Windows services, previously known as NT services, are applications that are installed on the system as system services. In other words, Windows services are applications that run in the background with the Windows operating system. The primary use of Windows services is to reduce the consumption of memory required for performing backend operations. Let's take an example to understand this easily.

Suppose you want to perform a variety of functions, such as monitor the performance of your computer or application, check the status of an application, and manage various devices, such as printers.

In such a case, you can use Windows services to reduce memory consumption. In addition, Windows services can run on your system even if you have not logged on to your computer. In addition, these services do not have any user interface.

2. Can you share a process between Windows services?

Yes, you can share a process between Windows services.

3. In .NET, which is the parent class to create all Windows services?

The ServiceBase class is the parent class to create all Windows services.

4. Which class in .NET is used to install a Windows service?

The ServiceInstaller class, also known as the project installer class, is used to install a Windows service.

5. While installing a Windows service, an EventLogInstaller class is automatically created to install the event log related to the particular service. Is it true?

Yes, it is true.

6. Which property of the ServiceBase class can be used to specify whether a service can be paused and resumed?

The CanPauseAndContinue property provides such type of service.

7. How to find out if a service present in different machine has been stopped or started

Use ServiceController Class present in System.ServiceProcess namespace to determine the status of the service. Have a timer in the application which is monitoring the service. The timer should poll service to determine its status.

ServiceController c = new ServiceController("", "");

8. Does windows service pick up any changes made to app.config when its running?

No. The service needs to be restarted to pick up any new changes made to the config file.

9. Debug a windows service

Below are the three methods

1.Create a new test class. Then call the functions from test class.

2.Add a line System.Diagnostics.Debugger.Break(); wherever you want to debug.At runtime a new instance will be created and debugging can be carried out in separate windows.

10. How to install a windows service

Go to visual studio command prompt. Navigate to path where the exe that you want to install is present.

To install, type

installutil projectname.exe

To uninstall, type

installutil /u projectname.exe

11. Can we pass values to windows service? If yes, how?

Yes, we can pass values to Windows Services

1) If you want to pass values at service startup, yo can send the values as command-line parameters. And (string[] args) of OnStart method will catch these parameters.

protected override void OnStart(string[] args) { }

2) If you want to pass values while service is running, you required to implement IPC (Interprocess communication) in Windows Service.

You can implement IPC by using any of following .NET technologies like NamedPipes, MSMQ, Remoting, TCP/IP Client/Service Programming or WCF Self Hosting Service.

1 comment:

  1. Wow! That's really great information guys.I know lot of new things here. Really great contribution.Thank you .

    Mobile Application Development Training in Chennai

    ReplyDelete