Windows Services

The tasks carried out by Windows Services are typically long-running tasks and have little or no direct interaction with a user. Many of the constituent parts of Windows and other products use Windows Services to carry out their functions. For example, some versions of Windows install an indexing service to enable searching of the file system. IIS and SQL Server both use Windows Services for important functionality. Such applications may be started when the computer is booted and often continue to run until the computer is shut down.

Example scenarios for creating your own Windows Services would include programs such as the following:

  • A file watcher—Suppose you are running an FTP server that enables users to place files in a particular directory. You could use a Windows Service to monitor and process files within that directory as they arrive. The service runs in the background and detects when files are changed or added within the directory, and then extracts information from these files in order to process orders, or update address and billing information. You will see an example of such a Windows Service later in this chapter.
  • An automated stock price reporter—You could build a system that extracts stock prices from a Web service or website and then e-mails the information to users. You could set thresholds such that an e-mail is sent only when the stock price reaches a certain price. This Windows Service can be automated to extract the information every 10 minutes, every 10 seconds, or whatever time interval you choose. Because a Windows Service can contain any logic that does not require a user interface, you have a lot of flexibility in constructing such applications.
  • A system activity logger—You might want to have a service that monitors a TCP channel and accepts activity log entries. The service could then place the log entries in an appropriate location, such as a database. Having a single service would relieve your application of the responsibility for knowing how activity is logged. They would only need to know how to send an entry to your service.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset