System [00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00] 1.0.3300.0 1.0.5000.0 2.0.0.0 4.0.0.0 Gtk# is thread aware, but not thread safe; See the <link location="node:gtk-sharp/programming/threads">Gtk# Thread Programming</link> for details. System.ComponentModel.Component System.ComponentModel.ISupportInitialize System.ComponentModel.DefaultEvent("Changed") System.IO.IODescription("")

Use to watch for changes in a specified directory. You can watch for changes in files and subdirectories of the specified directory. You can create a component to watch files on a local computer, a network drive, or a remote computer.

To watch for changes in all files, set the property to an empty string ("") or use wildcards ("*.*"). To watch a specific file, set the property to the file name. For example, to watch for changes in the file MyDoc.txt, set the property to "MyDoc.txt". You can also watch for changes in a certain type of file. For example, to watch for changes in text files, set the property to "*.txt".

There are several types of changes you can watch for in a directory or file. For example, you can watch for changes in Attributes, the LastWrite date and time, or the Size of files or directories. This is done by setting the property to one of the values. For more information on the type of changes you can watch, see .

You can watch for renaming, deletion, or creation of files or directories. For example, to watch for renaming of text files, set the property to "*.txt" and call the method with a specified for its parameter.

The Windows operating system notifies your component of file changes in a buffer created by the . If there are many changes in a short time, the buffer can overflow. This causes the component to lose track of changes in the directory, and it will only provide blanket notification. Increasing the size of the buffer with the property is expensive, as it comes from non-paged memory that cannot be swapped out to disk, so keep the buffer as small yet large enough to not miss any file change events. To avoid a buffer overflow, use the and properties so you can filter out unwanted change notifications.

For a list of initial property values for an instance of , see the constructor.

Please note the following when using the class.

Hidden files are not ignored.

In some systems, reports changes to files using the short 8.3 file name format. For example, a change to "LongFileName.LongExtension" could be reported as "LongFil~.Lon".

This class contains a link demand and an inheritance demand at the class level that applies to all members. A is thrown when either the immediate caller or the derived class does not have full-trust permission. For details about security demands, see Link Demands.

The maximum size you can set for the property for monitoring a directory over the network is 64 KB.

Running on Windows 98 is not supported.

## Copying and moving folders

The operating system and object interpret a cut-and-paste action or a move action as a rename action for a folder and its contents. If you cut and paste a folder with files into a folder being watched, the object reports only the folder as new, but not its contents because they are essentially only renamed.

To be notified that the contents of folders have been moved or copied into a watched folder, provide and event handler methods as suggested in the following table.

Event Handler

Events Handled

Performs

, ,

Report changes in file attributes, created files, and deleted files.

List the old and new paths of renamed files and folders, expanding recursively if needed.

## Events and Buffer Sizes

Note that several factors can affect which file system change events are raised, as described by the following:

Common file system operations might raise more than one event. For example, when a file is moved from one directory to another, several and some and events might be raised. Moving a file is a complex operation that consists of multiple simple operations, therefore raising multiple events. Likewise, some applications (for example, antivirus software) might cause additional file system events that are detected by .

The can watch disks as long as they are not switched or removed. The does not raise events for CDs and DVDs, because time stamps and properties cannot change. Remote computers must have one of the required platforms installed for the component to function properly.

If multiple objects are watching the same UNC path in Windows XP prior to Service Pack 1, or Windows 2000 SP2 or earlier, then only one of the objects will raise an event. On machines running Windows XP SP1 and newer, Windows 2000 SP3 or newer or Windows Server 2003, all objects will raise the appropriate events.

Note that a may miss an event when the buffer size is exceeded. To avoid missing events, follow these guidelines:

Increase the buffer size by setting the property.

Avoid watching files with long file names, because a long file name contributes to filling up the buffer. Consider renaming these files using shorter names.

Keep your event handling code as short as possible.

Listens to the file system change notifications and raises events when a directory, or file in a directory, changes.

- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  You cannot watch a remote computer that does not have Windows NT or Windows 2000. You cannot watch a remote Windows NT 4.0 computer from a Windows NT 4.0 computer.

  The following table shows initial property values for an instance of .

  Property

  Initial Value

  bitwise OR combination of LastWrite, FileName, and DirectoryName

  false

  "*.*" (Watch all files.)

  false

  8192

  empty string ("")

  The component will not watch the specified directory until the is set, and is true.

  Initializes a new instance of the class.

- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  The component will not watch the specified directory until the is set, and is true.

  The component can watch files on your personal computer, a network drive, or a remote computer.

  You cannot watch a remote computer that does not have Windows NT or Windows 2000. You cannot watch a remote Windows NT 4.0 computer from a Windows NT 4.0 computer. The property is set by default to watch all files.

  Initializes a new instance of the class, given the specified directory to monitor.

  The directory to monitor, in standard or Universal Naming Convention (UNC) notation.
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  The component will not watch the specified directory until the is set, and is true.

  The component can watch files on your personal computer, a network drive, or a remote computer.

  You cannot watch a remote computer that does not have Windows NT or Windows 2000. You cannot watch a remote Windows NT 4.0 computer from a Windows NT 4.0 computer.

  Initializes a new instance of the class, given the specified directory and type of files to monitor.

  The directory to monitor, in standard or Universal Naming Convention (UNC) notation.
  The type of files to watch. For example, "*.txt" watches for changes to all text files.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void

  The vsprvslong design environment uses this method to start the initialization of a component used on a form or used by another component. The method ends the initialization. Using the and methods prevents the control from being used before it is fully initialized.

  Begins the initialization of a used on a form or used by another component. The initialization occurs at run time.

- Event
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.IO.IODescription("Occurs when a file/directory change matches the filter")
  System.IO.FileSystemEventHandler

  The event is raised when changes are made to the size, system attributes, last write time, last access time, or security permissions of a file or directory in the directory being monitored.

  Common file system operations might raise more than one event. For example, when a file is moved from one directory to another, several and some and events might be raised. Moving a file is a complex operation that consists of multiple simple operations, therefore raising multiple events. Likewise, some applications (for example, antivirus software) might cause additional file system events that are detected by .

  Use to restrict the number of notifications raised when this event is handled.

  The event is raised unexpectedly when a file is renamed, but is not raised when a directory is renamed. To watch for renaming, use the event.

  The order in which the event is raised in relation to the other events may change when the property is not null.

  Occurs when a file or directory in the specified is changed.

- Event
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.IO.IODescription("Occurs when a file/directory creation matches the filter")
  System.IO.FileSystemEventHandler

  Some common occurrences, such as copying or moving a file or directory, do not correspond directly to an event, but these occurrences do cause events to be raised. When you copy a file or directory, the system raises a event in the directory to which the file was copied, if that directory is being watched. If the directory from which you copied was being watched by another instance of , no event would be raised. For example, you create two instances of . FileSystemWatcher1 is set to watch "C:\My Documents", and FileSystemWatcher2 is set to watch "C:\Your Documents". If you copy a file from "My Documents" into "Your Documents", a event will be raised by FileSystemWatcher2, but no event is raised for FileSystemWatcher1. Unlike copying, moving a file or directory would raise two events. From the previous example, if you moved a file from "My Documents" to "Your Documents", a event would be raised by FileSystemWatcher2 and a event would be raised by FileSystemWatcher1.

  Common file system operations might raise more than one event. For example, when a file is moved from one directory to another, several and some and events might be raised. Moving a file is a complex operation that consists of multiple simple operations, therefore raising multiple events. Likewise, some applications (for example, antivirus software) might cause additional file system events that are detected by .

  The order in which the event is raised in relation to the other events may change when the property is not null.

  The event is raised as soon as a file is created. If a file is being copied or transferred into a watched directory, the event will be raised immediately, followed by one or more events.

  Occurs when a file or directory in the specified is created.

- Event
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.IO.IODescription("Occurs when a file/directory deletion matches the filter")
  System.IO.FileSystemEventHandler

  Some common occurrences, such as copying or moving a file or directory, do not correspond directly to an event, but these occurrences do cause events to be raised. When you copy a file or directory, the system raises a event in the directory to which the file was copied, if that directory is being watched. If the directory from which you copied was being watched by another instance of , no event would be raised. For example, you create two instances of . FileSystemWatcher1 is set to watch "C:\My Documents", and FileSystemWatcher2 is set to watch "C:\Your Documents". If you copy a file from "My Documents" into "Your Documents", a event will be raised by FileSystemWatcher2, but no event is raised for FileSystemWatcher1. Unlike copying, moving a file or directory would raise two events. From the previous example, if you moved a file from "My Documents" to "Your Documents", a event would be raised by FileSystemWatcher2 and a event would be raised by FileSystemWatcher1.

  Common file system operations might raise more than one event. For example, when a file is moved from one directory to another, several and some and events might be raised. Moving a file is a complex operation that consists of multiple simple operations, therefore raising multiple events. Likewise, some applications (for example, antivirus software) might cause additional file system events that are detected by .

  The order in which the event is raised in relation to the other events may change when the property is not null.

  Occurs when a file or directory in the specified is deleted.

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void ``

  This method is called by the public method and the method. invokes the protected method with the parameter set to true. invokes with set to false.

  When the parameter is true, this method releases all resources held by any managed objects that this references. This method invokes the method of each referenced object.

  Releases the unmanaged resources used by the and optionally releases the managed resources.

  true to release both managed and unmanaged resources; false to release only unmanaged resources.
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.ComponentModel.DefaultValue(false)
  System.IO.IODescription("Flag to indicate if this instance is active")
  System.Boolean To be added: an object of type 'bool'

  The component will not raise events unless you set to true.

  The component will not watch the specified directory until the property has been set and is true.

  The method allows event handlers to be invoked to respond to file changes even if this property is set to false.

  Gets or sets a value indicating whether the component is enabled.

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void

  The vsprvslong design environment uses this method to end the initialization of a component used on a form or used by another component. The method starts the initialization. Using the and methods prevents the control from being used before it is fully initialized.

  Ends the initialization of a used on a form or used by another component. The initialization occurs at run time.

- Event
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.ComponentModel.Browsable(false)
  System.IO.ErrorEventHandler

  This event is raised whenever something prevents the object from monitoring changes. For example, if the object is monitoring changes in a remote directory and the connection to that directory is lost, the event is raised.

  The system notifies you of file changes, and it stores those changes in a buffer that the component creates and passes to the APIs. If there are many changes in a short time, the buffer can overflow. This causes the component to lose track of changes in the directory, and it will only provide blanket notification. Increasing the size of the buffer is expensive, because it comes from non paged memory that cannot be swapped out to disk, so keep the buffer as small as possible. To avoid a buffer overflow, use the , , and properties to filter out unwanted change notifications.

  Common file system operations might raise more than one event. For example, when a file is moved from one directory to another, several and some and events might be raised. Moving a file is a complex operation that consists of multiple simple operations, therefore raising multiple events. Likewise, some applications (for example, antivirus software) might cause additional file system events that are detected by .

  Occurs when the instance of is unable to continue monitoring changes or when the internal buffer overflows.

- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.ComponentModel.DefaultValue("*.*")
  System.ComponentModel.RecommendedAsConfigurable(true)
  System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
  System.IO.IODescription("File name filter pattern")
  System.String To be added: an object of type 'string'

  To watch changes in all files, set the property to an empty string (""). To watch a specific file, set the property to the file name. For example, to watch for changes in the file MyDoc.txt, set the property to "MyDoc.txt". You can also watch for changes in a certain type of file. For example, to watch for changes in any text files, set the property to "*.txt". Use of multiple filters such as "*.txt|*.doc" is not supported.

  The property can be changed after the object has started receiving events.

  For more information about filtering out unwanted notifications, see the , , and properties.

  accepts wildcards for matching files, as shown in the following examples.

  Filter string

  Watches the following files

  *.*

  All files (default). An empty string ("") also watches all files.

  *.txt

  All files with a "txt" extension.

  *recipe.doc

  All files ending in "recipe" with a "doc" extension.

  win*.xml

  All files beginning with "win" with an "xml" extension.

  Sales*200?.xls

  Matches the following:

  Sales July 2001.xlsSales Aug 2002.xlsSales March 2004.xls

  but does not match:

  Sales Nov 1999.xls

  MyReport.Doc

  Watches only MyReport.doc

  Gets or sets the filter string used to determine what files are monitored in a directory.

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void To be added. To be added.
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.ComponentModel.DefaultValue(false)
  System.IO.IODescription("Flag to indicate we want to watch subdirectories")
  System.Boolean To be added: an object of type 'bool'

  Set to true when you want to watch for change notifications for files and directories contained within the directory specified through the property, and its subdirectories. Setting the property to false helps reduce the number of notifications sent to the internal buffer. For more information on filtering out unwanted notifications, see the and properties.

  When true, is recursive through the entire sub tree, not just the immediate child directories. The relative path to a file or directory within the sub tree returns in the property of and the property of , depending on changes you are watching for. You can get the fully qualified path from the property of and the property of , depending on the changes you are watching for.

  If a directory is created in the sub tree of the directory you are watching, and is true, that directory will automatically be watched.

  Gets or sets a value indicating whether subdirectories within the specified path should be monitored.

- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.ComponentModel.Browsable(false)
  System.ComponentModel.DefaultValue(8192)
  System.Int32 To be added: an object of type 'int'

  You can set the buffer to 4 KB or larger, but it must not exceed 64 KB. If you try to set the property to less than 4096 bytes, your value is discarded and the property is set to 4096 bytes. For best performance, use a multiple of 4 KB on Intel-based computers.

  The system notifies the component of file changes, and it stores those changes in a buffer the component creates and passes to the APIs. Each event can use up to 16 bytes of memory, not including the file name. If there are many changes in a short time, the buffer can overflow. This causes the component to lose track of changes in the directory, and it will only provide blanket notification. Increasing the size of the buffer can prevent missing file system change events. However, increasing buffer size is expensive, because it comes from non-paged memory that cannot be swapped out to disk, so keep the buffer as small as possible. To avoid a buffer overflow, use the and properties to filter out unwanted change notifications.

  Gets or sets the size (in bytes) of the internal buffer.

- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.ComponentModel.DefaultValue(Mono.Cecil.CustomAttributeArgument)
  System.IO.IODescription("Flag to indicate which change event we want to monitor")
  System.IO.NotifyFilters To be added: an object of type 'NotifyFilters'

  You can combine the members of the enumeration to watch for more than one type of change at a time. For example, you can watch for changes in size of a file, and for changes in the LastWrite time. This raises an event anytime there is a change in file or folder size, or a change in the LastWrite time of the file or folder.

  This is one way to filter out unwanted notifications. For more information on filtering out unwanted notifications, see the , , and properties.

  Gets or sets the type of changes to watch for.

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void ``

  is called when changes are made to the size, system attributes, last write time, last access time, or security permissions of a file or directory in the directory being monitored.

  Use the property to restrict the number of events raised when the event is handled.

  The event is raised as soon as a file is created. If a file is being copied or transferred into a watched directory, the event will be raised immediately, followed by one or more events.

  Raising an event invokes the event handler through a delegate. For more information, see [<topic://cpconProvidingEventFunctionality>].

  Raises the event.

  A that contains the event data.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void ``

  is called when a file or directory is created in the directory being monitored.

  Some common occurrences, such as copying or moving a file or directory, do not correspond directly to an event, but these occurrences do cause events to be raised. When you copy a file or directory, the system raises a event in the directory to which the file was copied, if that directory is being watched. If the directory from which you copied was being watched by another instance of , no event would be raised. For example, you create two instances of . FileSystemWatcher1 is set to watch "C:\My Documents", and FileSystemWatcher2 is set to watch "C:\Your Documents". If you copy a file from "My Documents" and paste it into "Your Documents", a event will be raised in FileSystemWatcher2, but no event is raised for FileSystemWatcher1. Unlike copying, moving a file or directory raises two events. From the previous example, if you moved a file from "My Documents" to "Your Documents", a event would be raised in FileSystemWatcher2 and a event would be raised in FileSystemWatcher1.

  The event is raised as soon as a file is created. If a file is being copied or transferred into a watched directory, the event will be raised immediately, followed by one or more events.

  Raising an event invokes the event handler through a delegate. For more information, see [<topic://cpconProvidingEventFunctionality>].

  Raises the event.

  A that contains the event data.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void ``

  is called when a file or directory, within the directory being monitored, is deleted.

  Some common occurrences, such as copying or moving a file or directory, do not correspond directly to an event, but these occurrences do cause events to be raised. When you copy a file or directory, the system raises a event in the directory to which the file was copied, if that directory is being watched. If the directory from which you copied was being watched by another instance of , no event would be raised. For example, you create two instances of . FileSystemWatcher1 is set to watch "C:\My Documents", and FileSystemWatcher2 is set to watch "C:\Your Documents". If you copy a file from "My Documents" into "Your Documents", a event will be raised by FileSystemWatcher2, but no event is raised for FileSystemWatcher1. Unlike copying, moving a file or directory raises two events. From the previous example, if you moved a file from "My Documents" to "Your Documents", a event would be raised by FileSystemWatcher2 and a event would be raised by FileSystemWatcher1.

  Raising an event invokes the event handler through a delegate. For more information, see [<topic://cpconProvidingEventFunctionality>].

  Raises the event.

  A that contains the event data.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void ``

  is called when an error occurs.

  Raising an event invokes the event handler through a delegate. For more information, see [<topic://cpconProvidingEventFunctionality>].

  Raises the event.

  An that contains the event data.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void ``

  is called when a file or directory within the directory being monitored is renamed.

  Raising an event invokes the event handler through a delegate. For more information, see [<topic://cpconProvidingEventFunctionality>].

  Raises the event.

  A that contains the event data.
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.ComponentModel.DefaultValue("")
  System.ComponentModel.Editor("System.Diagnostics.Design.FSWPathEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
  System.ComponentModel.RecommendedAsConfigurable(true)
  System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
  System.IO.IODescription("The directory to monitor")
  System.String To be added: an object of type 'string'

  This is a fully qualified path to a directory. If the property is true, this directory is the root at which the system watches for changes; otherwise it is the only directory watched. To watch a specific file, set the property to the fully qualified, correct directory, and the property to the file name.

  The property supports Universal Naming Convention (UNC) paths.

  This property must be set before the component can watch for changes.

  When a directory is renamed, the automatically reattaches itself to the newly renamed item. For example, if you set the property to "C:\My Documents" and then manually rename the directory to "C:\Your Documents", the component continues listening for change notifications on the newly renamed directory. However, when you ask for the property, it contains the old path. This happens because the component determines what directory watches based on the handle, rather than the name of the directory. Renaming does not affect the handle. So, if you destroy the component, and then recreate it without updating the property, your application will fail because the directory no longer exists.

  Gets or sets the path of the directory to watch.

- Event
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.IO.IODescription("Occurs when a file/directory rename matches the filter")
  System.IO.RenamedEventHandler

  Renaming the directory you are watching will not raise a notification. Notifications are only raised for entries inside the directory you are watching.

  Occurs when a file or directory in the specified is renamed.

- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.ComponentModel.Browsable(false)
  System.ComponentModel.ISite To be added: an object of type 'ComponentModel.ISite'

  Sites bind a to a and enable communication between them, as well as provide a way for the container to manage its components.

  Gets or sets an for the .

- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.ComponentModel.Browsable(false)
  System.ComponentModel.DefaultValue(null)
  System.IO.IODescription("The object used to marshal the event handler calls resulting from a directory change")
  System.ComponentModel.ISynchronizeInvoke To be added: an object of type 'ComponentModel.ISynchronizeInvoke'

  When is null, methods handling the , , , and events are called on a thread from the system thread pool. For more information on system thread pools, see .

  When the , , , and events are handled by a visual Windows Forms component, such as a , accessing the component through the system thread pool might not work, or may result in an exception. Avoid this by setting to a Windows Forms component, which causes the methods that handle the , , , and events to be called on the same thread on which the component was created.

  If the is used inside vsprvslong in a Windows Forms designer, automatically sets to the control that contains the . For example, if you place a on a designer for Form1 (which inherits from ) the property of is set to the instance of Form1.

  Gets or sets the object used to marshal the event handler calls issued as a result of a directory change.

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.IO.WaitForChangedResult ``

  This method waits indefinitely until the first change occurs and then returns. This is the same as using with the parameter set to -1.

  This method allows an event handler to be invoked to respond to file changes even if the property is set to false.

  In some systems, reports changes to files using the short 8.3 file name format. For example, a change to "LongFileName.LongExtension" could be reported as "LongFi~.Lon".

  A synchronous method that returns a structure that contains specific information on the change that occurred, given the type of change you want to monitor.

  A that contains specific information on the change that occurred.

  The to watch for.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.IO.WaitForChangedResult `` ``

  This method waits until a change occurs or it has timed out. A value of -1 for the parameter means wait indefinitely.

  This method allows an event handler to be invoked to respond to file changes even if the property is set to false.

  In some systems, reports changes to files using the short 8.3 file name format. For example, a change to "LongFileName.LongExtension" could be reported as "LongFi~.Lon".

  A synchronous method that returns a structure that contains specific information on the change that occurred, given the type of change you want to monitor and the time (in milliseconds) to wait before timing out.

  A that contains specific information on the change that occurred.

  The to watch for. The time (in milliseconds) to wait before timing out.