Chapter 10. Building Windows Services and Console Applications with VB .NET

IN THIS CHAPTER

Visual Basic .NET lets you build Windows Services natively in VB for the first time. Windows Services, formerly called NT Services, are potentially long-running executables that can start without a user logging in, can be paused and restarted, and can be configured to run under different security contexts. Windows Services had been the domain of C++ developers until now, when the .NET Framework opens the ability for any .NET language to create services.

Windows Services should not be confused with XML Web Services, which are implemented as a different project type. Services are supported on only Windows NT, Windows 2000, and Windows XP.

Services work a little differently from just about any other project type. You cannot start a project within the Visual Studio .NET environment and step through it for debugging purposes. You must install your application as a service with the operating system in order for it to run. Then, after it is running, you can attach a debugger to it. Because Windows Services do not have a user interface, they typically use the event log to communicate problems or messages to the user or administrator.

Services are useful in certain circumstances. For example, I worked on an application in which files could arrive at any time, via FTP. A service ran that monitored a directory, and received an event when a file was added to the directory. The service then went about processing the file as necessary. This was a perfect use for a service: It needed to run all the time, regardless of whether anyone was logged in. The files could arrive at any time, so the service had to be running constantly. Finally, no user interface was necessary.

Once again, you will dive into a project and get it working, and then examine its various pieces. The service you will write checks the processor usage on a regular basis and logs the information to a file. This service introduces something new: capturing performance counters. This will be woven into your first service.

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

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