(How)
C^# You Are - 10 June 2007
This week's questions are related to the FileSystemWatcher.
After you have answered these questions refer to the article Using the FileSystemWatcher
for the answers.
- What file events can be monitored by FileSystemWatcher? Answer
Created, Changed, Deleted and Renamed.
- What events should be monitored when watching for file changes? Answer
In addition to Changed Renamed should be monitored.
Saving files can involve the creation and renaming of a temporary file to avoid
lose the original file in case of errors.
- How can you monitor for changes to multiple file types? Answer
FileSystemWatcher can either monitor all files in a directory (and
children) or a specific file type. A single file mask can be specified.
If the multiple file types can not be specified using a single file mask then filtering
will have to occur using code.
- Why might files be locked when using the FileSystemWatcher? Answer
Because the events are raised as they occur the process causing the event probably
will not have released the file yet. Therefore it is the general case where
a file will be locked when the event is raised by FileSystemWatcher.
Handlers must be ready to handle this case.
- What file systems will FileSystemWatcher not work with? Answer
FileSystemWatcher will not work with removable drives including
CDs and DVDs. This is a limitation of the Win32 API. For CDs and DVDs
it makes a lot of sense since the file contents can not change anyway.