Skip to Content
Professional Visual Basic 2012 and .NET 4.5 Programming
book

Professional Visual Basic 2012 and .NET 4.5 Programming

by Bill Sheldon, Billy Hollis, Rob Windsor, David McCarter, Gastón Hillar, Todd Herman
January 2013
Intermediate to advanced
912 pages
26h 58m
English
Wrox
Content preview from Professional Visual Basic 2012 and .NET 4.5 Programming

Creating a File Watcher Service

To illustrate the outlined steps, the following example monitors a particular directory and reacts when a new or changed file is placed in the directory. The example Windows Service application waits for those files, extracts information from them, and then logs an event to a system log to record the file change.

Creating a Solution for the Windows Service

First, you need an appropriate solution in place to hold the Windows Service. To do so, follow these steps:

1. Create a new Windows Service project using Visual Studio. Name the project ProVB_FileWatcherService.
2. In the Solution Explorer, rename Service1.vb to FileWatcherService.vb. You will be prompted to also change the class name.
3. Click the design surface for FileWatcherService.vb. In the Properties window, change the ServiceName property from Service1 to FileWatcherService. Step 2 changes the name of the class on which the service is based, while the ServiceName property changes the name of the service as shown in the Service Control Manager.
4. Add an installer to the project. Go back to the design surface for FileWatcherService and right-click it. Select Add Installer. A new file called ProjectInstaller.vb is created and added to the project. The ProjectInstaller.vb file has two components added to its design surface: ServiceProcessInstaller1 and ServiceInstaller1.
5. On the ProjectInstaller.vb design surface, highlight the ServiceProcessInstaller1 control. In its Properties window, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Visual Basic 2012 Programmer's Reference

Visual Basic 2012 Programmer's Reference

Rod Stephens

Publisher Resources

ISBN: 9781118332139Purchase book