Monitor the File System for Changes

Problem

You need to react when a file system change is detected in a specific path (such as a file modification or creation).

Solution

Use the FileSystemWatcher component, which monitors a path and raises events when files or directories are modified.

Discussion

When linking together multiple applications and business processes, it’s often necessary to create a program that waits idly and only springs into action when a new file is received or changed. You can create this type of program by scanning a directory periodically, but you face a key tradeoff. The more often you scan, the more system resources you waste. The less often you scan, the longer it might take to detect the appropriate event. The solution is to ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.