Home   |   QuickStart Welcome   |   ASP.NET   |   Web Services   |   How Do I...?   
  |   I want my samples in...      

How Do I...? Common Tasks QuickStart Tutorial

How Do I...Write a Simple Service Application?



Microsoft Windows NT services enable you to create long running executable applications that run in their own Windows sessions. These services can be automatically started when the computer boots, can be paused and restarted, and typically do not show any user interface. This makes services ideal for use on a server or whenever you need long-running functionality that does not interfere with other users who are working on the same computer. You can also run services in the security context of a specific user account that is different from the logged-on user or the default computer account. For more information about services and Windows sessions, see the "About Services" section in the Platform SDK documentation in MSDN Online.

Using the .NET Framework, you can easily create services by creating an application that is installed as a service. For example, suppose you want to monitor performance counter data and react to threshold values. You could do this by writing an NT service and deploying it to the computer that has the counters you want to monitor.

The following sample is a simple service application. You can install it using the .NET Framework SDK Installation Utility. From a command prompt run:
> InstallUtil.exe SimpleService.exe


After the installation is completed you can start the Hello World Service from the Services Management Console. After the service starts you should see the service's event log being filled with greetings from the sample service. You can use the Services Management Console to pause, continue, start, and stop the service, and observe how such operations affect the messages written to the event log. After you are done experimenting with the sample, you can uninstall the service by running the following command from the command window (you should stop the service before uninstalling it):
> InstallUtil.exe /u SimpleService.exe

Example

VB SimpleService.exe
View Source
[This sample can be found at C:\DevFusion.Data\legacy\quickstart.developerfusion.co.uk\QuickStart\howto\samples\Services\ServiceApplication\SimpleService\]



Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2004 Microsoft Corporation. All rights reserved.