FileSystemWatcher.EnableRaisingEvents Property


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

Namespace:   System.IO
Assembly:  System (in System.dll)

member EnableRaisingEvents : bool with get, set

Property Value

Type: System.Boolean

true if the component is enabled; otherwise, false. The default is false. If you are using the component on a designer in Visual Studio 2005, the default is true.

Exception Condition

The FileSystemWatcher object has been disposed.


The current operating system is not Microsoft Windows NT or later.


The directory specified in Path could not be found.


Path has not been set or is invalid.

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


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

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

The following example creates a FileSystemWatcher to watch the directory specified at run time. The component is set to watch for changes in LastWrite and LastAccess time, the creation, deletion, or renaming of text files in the directory. If a file is changed, created, or deleted, the path to the file prints to the console. When a file is renamed, the old and new paths print to the console.

Use the System.Diagnostics and System.IO namespaces for this example.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1
Return to top