C # FileSystemWatcher class monitor file attributes

Attributes:

Path-- This attribute tells the FileSystemWatcher which path it needs to be monitored. For example, if we set this property to "C: Temp", objects to monitor all changes that occur in the directory.
IncludeSubDirectories-- this property should monitor whether the FileSystemWatcher change subdirectory.
Filter-- This property allows you to filter out certain types of files changes occur. For example, if we only want to be modified / new / delete notification submitted in TXT file, you can set this property to "* txt". In dealing with high traffic or large directories, this property is very convenient to use.
event

Changed-- added to the monitored directory when a file is modified, the submission of this event. It is worth noting that this event may be submitted multiple times, even though the contents of the file only occur a change. This is because when you save the file, the other file attributes have changed.
Created-- when the monitored directory to create a new document, submitted this event. If you plan to use this event to move the new event, you must write some error handling code in the event handler that can handle the current file being used by another process. The reason for this is because Created event might be submitted before the process of establishing documents released documents. If you do not prepare properly handling code in this case, it may appear abnormal.
Deleted-- when the monitored directory has a file is deleted, the submission of this event.
Renamed-- when the monitored directory has a file is renamed, to submit this event.
Note: If you have not EnableRaisingEvents set to true, the system will not submit to any event. If sometimes the FileSystemWatcher does not seem to work, first check EnableRaisingEvents, make sure it is set to true.

Event Processing

When a FileSystemWatcher to call an event handler, which contains two independent variables - called "sender" of the object and called "e" of FileSystemEventArgs object. Since the variable of interest is FileSystemEventArgs arguments. The reason there is an event of this object contains. The following are some of the attributes FileSystemEventArgs object:

Attributes:

Name-- the name of the file attribute manipulation event is submitted. Which does not contain the path to the file - the file contains only using the event to be submitted or directory names.
ChangeType-- This is a WatcherChangeTypes, indicating which types of events to be submitted. Valid values include: Changed, the Created, Deleted, Renamed
FullPath-- this property contains the full path of the file to be submitted to the event, including file and directory names.

FileSystemWatcher objects complete directory monitoring work for you. If the new, updated, or deleted a file, FileSystemWatcher will submit an event, you notice the occurrence of a change. In this way, after a new file, your program will know immediately you can use this file. Notice an immediate change makes your system work more efficiently, because you can not always "investigation" occurred directory changes, and there will be no loss of time between the two directory scan.

Guess you like

Origin www.cnblogs.com/magicalpig/p/11736467.html