What is “Windows Service Development”?

To answer that, first I have to define what a Windows Service is.  The Windows OS has the ability to run (or “execute”) several diffeMMCrent types of programs.  The types of programs most Windows users are familiar with are the ones stored on disk with the name “.exe” appended to the end of its file name.  Users generally double-click the file with their mouse (or a link to the file or an icon representing it) and the program is then loaded and executed.  These programs generally have a GUI.  Sometimes they have a plain old text (or “console”) interface.  But, they usually have some kind of a user interface.  These programs also require a user to be actively logged onto the machine.  These programs also run with the same security as the logged on user.  Any permissions the user has, so do the programs the user started.

Windows Services are different types of programs.  They’re not Windows Services in Task Managerlaunched (or started) directly by the user.  They generally start when the OS starts and do not require that a user be logged on to run.  As such, since they can run without a user interacting with them, they don’t have a user interface.  They run in the background.

A typical Windows machine has dozens of Windows Services running all the time.  They range from anti-virus programs, to web servers, to database servers.  Even some viruses run as Windows Services.

Development:

Windows Service Development is the act of designing and writing one of these Windows Service programs.  They can be written in pretty much any language that a normal Windows program can be written in.  Most Windows Service applications are written in C or C++.  Though, more and more are written in a language that supports the .NET framework, such as C# or VB.NET.

A Windows Service program can be written to respond to 4 different events:

  1. Start
  2. Stop
  3. Pause
  4. Resume

Start and Stop events are required events.  In other words, you have to write event handlers for those two events.  The pause and resume events are optional.

In the start event handler, you generally spin off a new thread and in that thread create an infinite loop, exiting only when the stop event is triggered.  Inside this loop, you perform your work.

Leave a Reply