FileSystemWatcher FileSystemWatcher FileSystemWatcher FileSystemWatcher Class

定義

當目錄或目錄內的檔案變更時,接聽 (Listen) 檔案系統變更告知並引發事件。Listens to the file system change notifications and raises events when a directory, or file in a directory, changes.

public ref class FileSystemWatcher : System::ComponentModel::Component, System::ComponentModel::ISupportInitialize
[System.IO.IODescription("")]
[System.IO.IODescription("FileSystemWatcherDesc")]
public class FileSystemWatcher : System.ComponentModel.Component, System.ComponentModel.ISupportInitialize
type FileSystemWatcher = class
    inherit Component
    interface ISupportInitialize
Public Class FileSystemWatcher
Inherits Component
Implements ISupportInitialize
繼承
屬性
實作

範例

下列範例會建立FileSystemWatcher監看在執行階段指定的目錄。The following example creates a FileSystemWatcher to watch the directory specified at run time. 元件會設定為監看的變更LastWriteLastAccess時間、 建立、 刪除或重新命名的目錄中的文字檔案。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.

#using <System.dll>

using namespace System;
using namespace System::IO;
using namespace System::Security::Permissions;

public ref class Watcher
{
private:
   // Define the event handlers.
   static void OnChanged( Object^ /*source*/, FileSystemEventArgs^ e )
   {
      // Specify what is done when a file is changed, created, or deleted.
      Console::WriteLine( "File: {0} {1}", e->FullPath, e->ChangeType );
   }

   static void OnRenamed( Object^ /*source*/, RenamedEventArgs^ e )
   {
      // Specify what is done when a file is renamed.
      Console::WriteLine( "File: {0} renamed to {1}", e->OldFullPath, e->FullPath );
   }

public:
   [PermissionSet(SecurityAction::Demand, Name="FullTrust")]
   int static run()
   {
      array<String^>^args = System::Environment::GetCommandLineArgs();

      // If a directory is not specified, exit program.
      if ( args->Length != 2 )
      {
         // Display the proper way to call the program.
         Console::WriteLine( "Usage: Watcher.exe (directory)" );
         return 0;
      }

      // Create a new FileSystemWatcher and set its properties.
      FileSystemWatcher^ watcher = gcnew FileSystemWatcher;
      watcher->Path = args[ 1 ];

      /* Watch for changes in LastAccess and LastWrite times, and 
          the renaming of files or directories. */
      watcher->NotifyFilter = static_cast<NotifyFilters>(NotifyFilters::LastAccess |
            NotifyFilters::LastWrite | NotifyFilters::FileName | NotifyFilters::DirectoryName);

      // Only watch text files.
      watcher->Filter = "*.txt";

      // Add event handlers.
      watcher->Changed += gcnew FileSystemEventHandler( Watcher::OnChanged );
      watcher->Created += gcnew FileSystemEventHandler( Watcher::OnChanged );
      watcher->Deleted += gcnew FileSystemEventHandler( Watcher::OnChanged );
      watcher->Renamed += gcnew RenamedEventHandler( Watcher::OnRenamed );

      // Begin watching.
      watcher->EnableRaisingEvents = true;

      // Wait for the user to quit the program.
      Console::WriteLine( "Press \'q\' to quit the sample." );
      while ( Console::Read() != 'q' );

      return 0;
   }
};

int main() {
   Watcher::run();
}
using System;
using System.IO;
using System.Security.Permissions;

public class Watcher
{
    public static void Main()
    {
        Run();
    }

    [PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
    private static void Run()
    {
        string[] args = Environment.GetCommandLineArgs();

        // If a directory is not specified, exit program.
        if (args.Length != 2)
        {
            // Display the proper way to call the program.
            Console.WriteLine("Usage: Watcher.exe (directory)");
            return;
        }

        // Create a new FileSystemWatcher and set its properties.
        using (FileSystemWatcher watcher = new FileSystemWatcher())
        {
            watcher.Path = args[1];

            // Watch for changes in LastAccess and LastWrite times, and
            // the renaming of files or directories.
            watcher.NotifyFilter = NotifyFilters.LastAccess
                                 | NotifyFilters.LastWrite
                                 | NotifyFilters.FileName
                                 | NotifyFilters.DirectoryName;

            // Only watch text files.
            watcher.Filter = "*.txt";

            // Add event handlers.
            watcher.Changed += OnChanged;
            watcher.Created += OnChanged;
            watcher.Deleted += OnChanged;
            watcher.Renamed += OnRenamed;

            // Begin watching.
            watcher.EnableRaisingEvents = true;

            // Wait for the user to quit the program.
            Console.WriteLine("Press 'q' to quit the sample.");
            while (Console.Read() != 'q') ;
        }
    }

    // Define the event handlers.
    private static void OnChanged(object source, FileSystemEventArgs e) =>
        // Specify what is done when a file is changed, created, or deleted.
        Console.WriteLine($"File: {e.FullPath} {e.ChangeType}");

    private static void OnRenamed(object source, RenamedEventArgs e) =>
        // Specify what is done when a file is renamed.
        Console.WriteLine($"File: {e.OldFullPath} renamed to {e.FullPath}");
}
Imports System
Imports System.IO
Imports System.Security.Permissions
Imports Microsoft.VisualBasic

Public Class Watcher

    Public Shared Sub Main()

        Run()

    End Sub

    <PermissionSet(SecurityAction.Demand, Name:="FullTrust")>
    Private Shared Sub Run()

        Dim args() As String = Environment.GetCommandLineArgs()

        ' If a directory is not specified, exit the program.
        If args.Length <> 2 Then
            ' Display the proper way to call the program.
            Console.WriteLine("Usage: Watcher.exe (directory)")
            Return
        End If

        ' Create a new FileSystemWatcher and set its properties.
        Using watcher As New FileSystemWatcher()
            watcher.Path = args(1)

            ' Watch for changes in LastAccess and LastWrite times, and
            ' the renaming of files or directories. 
            watcher.NotifyFilter = (NotifyFilters.LastAccess _
                                 Or NotifyFilters.LastWrite _
                                 Or NotifyFilters.FileName _
                                 Or NotifyFilters.DirectoryName)

            ' Only watch text files.
            watcher.Filter = "*.txt"

            ' Add event handlers.
            AddHandler watcher.Changed, AddressOf OnChanged
            AddHandler watcher.Created, AddressOf OnChanged
            AddHandler watcher.Deleted, AddressOf OnChanged
            AddHandler watcher.Renamed, AddressOf OnRenamed

            ' Begin watching.
            watcher.EnableRaisingEvents = True

            ' Wait for the user to quit the program.
            Console.WriteLine("Press 'q' to quit the sample.")
            While Chr(Console.Read()) <> "q"c
            End While
        End Using
    End Sub

    ' Define the event handlers.
    Private Shared Sub OnChanged(source As Object, e As FileSystemEventArgs)
        ' Specify what is done when a file is changed, created, or deleted.
        Console.WriteLine($"File: {e.FullPath} {e.ChangeType}")
    End Sub

    Private Shared Sub OnRenamed(source As Object, e As RenamedEventArgs)
        ' Specify what is done when a file is renamed.
        Console.WriteLine($"File: {e.OldFullPath} renamed to {e.FullPath}")
    End Sub

End Class

備註

使用FileSystemWatcher監看的指定目錄中的變更。Use FileSystemWatcher 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.

若要觀看的所有檔案中的變更,請設定Filter屬性設為空字串 ("") 或使用萬用字元 ("*。*")。To watch for changes in all files, set the Filter property to an empty string ("") or use wildcards ("*.*"). 若要觀看的特定檔案,設定Filter屬性設為檔案名稱。To watch a specific file, set the Filter property to the file name. 例如,若要觀看 MyDoc.txt 檔案中的變更,請設定Filter"MyDoc.txt"的屬性。For example, to watch for changes in the file MyDoc.txt, set the Filter property to "MyDoc.txt". 您也可以觀看某種類型的檔案中的變更。You can also watch for changes in a certain type of file. 例如,若要監看的文字檔案中的變更,將Filter屬性為"*.txt"。For example, to watch for changes in text files, set the Filter property to "*.txt".

有數種您可以監看目錄或檔案中的變更。There are several types of changes you can watch for in a directory or file. 例如,您可以觀看中的變更Attributes,則LastWrite日期和時間,或Size的檔案或目錄。For example, you can watch for changes in Attributes, the LastWrite date and time, or the Size of files or directories. 這是藉由設定NotifyFilter屬性設為其中的NotifyFilters值。This is done by setting the NotifyFilter property to one of the NotifyFilters values. 如需詳細資訊的變更類型可以觀看,請參閱NotifyFiltersFor more information on the type of changes you can watch, see NotifyFilters.

您可以觀看的重新命名、 刪除或建立的檔案或目錄。You can watch for renaming, deletion, or creation of files or directories. 例如,若要觀看的文字檔案重新命名,設定Filter屬性設為"*.txt",並呼叫WaitForChanged方法Renamed其參數所指定。For example, to watch for renaming of text files, set the Filter property to "*.txt" and call the WaitForChanged method with a Renamed specified for its parameter.

Windows 作業系統會通知您有在緩衝區中所建立的檔案變更的元件FileSystemWatcherThe Windows operating system notifies your component of file changes in a buffer created by the FileSystemWatcher. 如果在短時間內有許多變更,緩衝區會溢位。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. 使用緩衝區的大小增加InternalBufferSize屬性很高,因為它來自無法空出給磁碟,所以還保留較少的緩衝區的非分頁記憶體大型足以不錯過任何檔案變更的事件。Increasing the size of the buffer with the InternalBufferSize 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. 若要避免緩衝區溢位,請使用NotifyFilterIncludeSubdirectories屬性,如此您可以篩選掉不必要的變更通知。To avoid a buffer overflow, use the NotifyFilter and IncludeSubdirectories properties so you can filter out unwanted change notifications.

如需執行個體的初始屬性值的清單FileSystemWatcher,請參閱FileSystemWatcher建構函式。For a list of initial property values for an instance of FileSystemWatcher, see the FileSystemWatcher constructor.

使用時,請注意下列FileSystemWatcher類別。Please note the following when using the FileSystemWatcher class.

  • 隱藏的檔案不會被忽略。Hidden files are not ignored.

  • 在某些系統中,FileSystemWatcher報告變更,使用簡短的 8.3 檔案名稱格式的檔案。In some systems, FileSystemWatcher reports changes to files using the short 8.3 file name format. 例如,"LongFileName.LongExtension 」 的變更無法回報為 「 LongFil ~。Lon"。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. ASecurityException立即呼叫端或衍生的類別不具有完全信任權限時,會擲回。A SecurityException 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.

  • 您可以設定的大小上限InternalBufferSize屬性透過網路監視的目錄是 64 KB。The maximum size you can set for the InternalBufferSize property for monitoring a directory over the network is 64 KB.

注意

執行FileSystemWatcher在 Windows 98 不支援。Running FileSystemWatcher on Windows 98 is not supported.

複製和移動資料夾Copying and moving folders

作業系統和FileSystemWatcher物件解譯剪下和貼上動作或 move 動作的資料夾和其內容重新命名動作。The operating system and FileSystemWatcher object interpret a cut-and-paste action or a move action as a rename action for a folder and its contents. 如果您剪下並將資料夾與檔案貼到正在監看資料夾FileSystemWatcher物件會報告為新的資料夾,但不是包括其內容因為基本上只重新命名。If you cut and paste a folder with files into a folder being watched, the FileSystemWatcher object reports only the folder as new, but not its contents because they are essentially only renamed.

若要收到資料夾的內容已移動或複製到監看的資料夾中,提供OnChangedOnRenamed事件處理常式方法下, 表中的建議。To be notified that the contents of folders have been moved or copied into a watched folder, provide OnChanged and OnRenamed event handler methods as suggested in the following table.

事件處理常式Event Handler 處理的事件Events Handled 執行Performs
OnChanged ChangedCreatedDeletedChanged, Created, Deleted 報告檔案屬性、 建立的檔案和已刪除的檔案中的變更。Report changes in file attributes, created files, and deleted files.
OnRenamed Renamed 列出舊和新的路徑重新命名的檔案和資料夾,如有需要請展開以遞迴方式。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. 比方說,當檔案移到另一個、 數個目錄之間OnChanged和某些OnCreatedOnDeleted可能引發事件。For example, when a file is moved from one directory to another, several OnChanged and some OnCreated and OnDeleted events might be raised. 移動檔案簡單的多個作業所組成的複雜作業,因此會引發多個事件。Moving a file is a complex operation that consists of multiple simple operations, therefore raising multiple events. 同樣地,某些應用程式 (例如,防毒軟體) 可能會導致所偵測到的其他檔案系統事件FileSystemWatcherLikewise, some applications (for example, antivirus software) might cause additional file system events that are detected by FileSystemWatcher.

  • FileSystemWatcher可以觀看磁碟,只要它們不會切換,或移除。The FileSystemWatcher can watch disks as long as they are not switched or removed. FileSystemWatcher不會引發事件的 Cd 與 Dvd,因為時間戳記和屬性無法變更。The FileSystemWatcher 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.

  • 如果有多個FileSystemWatcher物件所監看 Windows XP Service Pack 1 之前相同的 UNC 路徑,或 Windows 2000 SP2 或更早版本,則只有其中一個物件,則會引發事件。If multiple FileSystemWatcher 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. 在機器上執行 Windows XP SP1 和更新版本中,Windows 2000 SP3 或更新版本或 Windows Server 2003,所有FileSystemWatcher物件將會引發適當的事件。On machines running Windows XP SP1 and newer, Windows 2000 SP3 or newer or Windows Server 2003, all FileSystemWatcher objects will raise the appropriate events.

請注意,FileSystemWatcher可能會遺失超過緩衝區大小時的事件。Note that a FileSystemWatcher may miss an event when the buffer size is exceeded. 若要避免遺失事件,請遵循這些指導方針:To avoid missing events, follow these guidelines:

  • 藉由設定增加緩衝區大小InternalBufferSize屬性。Increase the buffer size by setting the InternalBufferSize 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.

建構函式

FileSystemWatcher() FileSystemWatcher() FileSystemWatcher() FileSystemWatcher()

初始化 FileSystemWatcher 類別的新執行個體。Initializes a new instance of the FileSystemWatcher class.

FileSystemWatcher(String) FileSystemWatcher(String) FileSystemWatcher(String) FileSystemWatcher(String)

提供要監視的指定目錄,來初始化 FileSystemWatcher 類別的新執行個體。Initializes a new instance of the FileSystemWatcher class, given the specified directory to monitor.

FileSystemWatcher(String, String) FileSystemWatcher(String, String) FileSystemWatcher(String, String) FileSystemWatcher(String, String)

提供要監視的指定目錄和檔案類型,來初始化 FileSystemWatcher 類別的新執行個體。Initializes a new instance of the FileSystemWatcher class, given the specified directory and type of files to monitor.

屬性

CanRaiseEvents CanRaiseEvents CanRaiseEvents CanRaiseEvents

取得值,指出元件是否能引發事件。Gets a value indicating whether the component can raise an event.

(Inherited from Component)
Container Container Container Container

取得包含 IContainerComponentGets the IContainer that contains the Component.

(Inherited from Component)
DesignMode DesignMode DesignMode DesignMode

取得值,指出 Component 目前是否處於設計模式。Gets a value that indicates whether the Component is currently in design mode.

(Inherited from Component)
EnableRaisingEvents EnableRaisingEvents EnableRaisingEvents EnableRaisingEvents

取得或設定數值,表示是否啟用元件。Gets or sets a value indicating whether the component is enabled.

Events Events Events Events

取得附加在這個 Component 上的事件處理常式清單。Gets the list of event handlers that are attached to this Component.

(Inherited from Component)
Filter Filter Filter Filter

取得或設定篩選字串,用以判斷在目錄中監視什麼檔案。Gets or sets the filter string used to determine what files are monitored in a directory.

Filters Filters Filters Filters
IncludeSubdirectories IncludeSubdirectories IncludeSubdirectories IncludeSubdirectories

取得或設定數值,表示是否應該監視指定路徑內的子目錄。Gets or sets a value indicating whether subdirectories within the specified path should be monitored.

InternalBufferSize InternalBufferSize InternalBufferSize InternalBufferSize

取得或設定內部緩衝區的大小 (以位元組為單位)。Gets or sets the size (in bytes) of the internal buffer.

NotifyFilter NotifyFilter NotifyFilter NotifyFilter

取得或設定要監看的變更類型。Gets or sets the type of changes to watch for.

Path Path Path Path

取得或設定要監看的目錄路徑。Gets or sets the path of the directory to watch.

Site Site Site Site

取得或設定 ISiteFileSystemWatcherGets or sets an ISite for the FileSystemWatcher.

SynchronizingObject SynchronizingObject SynchronizingObject SynchronizingObject

取得或設定物件,用以封送處理因目錄變更而發出的事件處理常式呼叫。Gets or sets the object used to marshal the event handler calls issued as a result of a directory change.

方法

BeginInit() BeginInit() BeginInit() BeginInit()

開始初始化用於表單或為另一個元件所使用的 FileSystemWatcherBegins the initialization of a FileSystemWatcher used on a form or used by another component. 初始化發生於執行階段。The initialization occurs at run time.

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Dispose() Dispose() Dispose() Dispose()
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

釋放 FileSystemWatcher 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。Releases the unmanaged resources used by the FileSystemWatcher and optionally releases the managed resources.

EndInit() EndInit() EndInit() EndInit()

結束用於表單上或用於另一個元件的 FileSystemWatcher 初始化。Ends the initialization of a FileSystemWatcher used on a form or used by another component. 初始化發生於執行階段。The initialization occurs at run time.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
Finalize() Finalize() Finalize() Finalize()
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetService(Type) GetService(Type) GetService(Type) GetService(Type)

傳回表示 Component 或其 Container 所提供之服務的物件。Returns an object that represents a service provided by the Component or by its Container.

(Inherited from Component)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

取得存留期服務物件,以控制這個執行個體的存留期原則。Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
OnChanged(FileSystemEventArgs) OnChanged(FileSystemEventArgs) OnChanged(FileSystemEventArgs) OnChanged(FileSystemEventArgs)

引發 Changed 事件。Raises the Changed event.

OnCreated(FileSystemEventArgs) OnCreated(FileSystemEventArgs) OnCreated(FileSystemEventArgs) OnCreated(FileSystemEventArgs)

引發 Created 事件。Raises the Created event.

OnDeleted(FileSystemEventArgs) OnDeleted(FileSystemEventArgs) OnDeleted(FileSystemEventArgs) OnDeleted(FileSystemEventArgs)

引發 Deleted 事件。Raises the Deleted event.

OnError(ErrorEventArgs) OnError(ErrorEventArgs) OnError(ErrorEventArgs) OnError(ErrorEventArgs)

引發 Error 事件。Raises the Error event.

OnRenamed(RenamedEventArgs) OnRenamed(RenamedEventArgs) OnRenamed(RenamedEventArgs) OnRenamed(RenamedEventArgs)

引發 Renamed 事件。Raises the Renamed event.

ToString() ToString() ToString() ToString()

傳回任何包含 Component 名稱的 StringReturns a String containing the name of the Component, if any. 不應覆寫此方法。This method should not be overridden.

(Inherited from Component)
WaitForChanged(WatcherChangeTypes) WaitForChanged(WatcherChangeTypes) WaitForChanged(WatcherChangeTypes) WaitForChanged(WatcherChangeTypes)

提供想要監視的變更類型,同步方法會傳回含有發生的變更之特定資訊的結構。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.

WaitForChanged(WatcherChangeTypes, Int32) WaitForChanged(WatcherChangeTypes, Int32) WaitForChanged(WatcherChangeTypes, Int32) WaitForChanged(WatcherChangeTypes, Int32)

提供您想要監視的變更類型和逾時前的等候時間 (以毫秒計),同步方法會傳回含有發生的變更之特定資訊的結構。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.

事件

Changed Changed Changed Changed

發生在指定 Path 內的檔案或目錄變更時。Occurs when a file or directory in the specified Path is changed.

Created Created Created Created

發生在指定 Path 內的檔案或目錄建立時。Occurs when a file or directory in the specified Path is created.

Deleted Deleted Deleted Deleted

發生在指定 Path 內的檔案或目錄刪除時。Occurs when a file or directory in the specified Path is deleted.

Disposed Disposed Disposed Disposed

當此元件由 Dispose() 方法的呼叫處置時發生。Occurs when the component is disposed by a call to the Dispose() method.

(Inherited from Component)
Error Error Error Error

FileSystemWatcher 執行個體無法繼續執行監視變更時或在內部緩衝區溢位時發生。Occurs when the instance of FileSystemWatcher is unable to continue monitoring changes or when the internal buffer overflows.

Renamed Renamed Renamed Renamed

發生在指定的 Path 內的檔案或目錄重新命名時。Occurs when a file or directory in the specified Path is renamed.

安全性

SecurityPermission
針對衍生自ProcessStartInfo類別。for deriving from the ProcessStartInfo class. 要求值: InheritanceDemand;具名使用權限集合: FullTrustDemand value: InheritanceDemand; Named Permission Sets: FullTrust.

適用於

另請參閱