作爲vb中的新手,我在我的FileSystemWatcher
中遇到了一些麻煩。由於一些不祥的原因,它不會觸發任何事件。我想檢查目錄中正在複製,刪除或編輯的文件。FileSystemWatcher沒有觸發事件
我很感激任何幫助!
這裏是我的代碼:
Public Class FileWatcher
Public Sub run(path As String)
Dim watcher As New FileSystemWatcher()
watcher.Path = path
watcher.Filter = "*.xml"
watcher.NotifyFilter = NotifyFilters.FileName Or NotifyFilters.LastWrite Or NotifyFilters.CreationTime
AddHandler watcher.Changed, AddressOf OnChanged
AddHandler watcher.Created, AddressOf OnChanged
AddHandler watcher.Deleted, AddressOf OnChanged
AddHandler watcher.Renamed, AddressOf OnRenamed
watcher.EnableRaisingEvents = True
End Sub
Public Function OnChanged(source As Object, e As FileSystemEventArgs) As String
' Returns file name for later use
Console.WriteLine("Monitoring: " + e.FullPath)
Return e.FullPath
End Function
Public Function OnRenamed(source As Object, e As RenamedEventArgs) As String
Console.WriteLine("Monitoring: " + e.FullPath)
Return e.FullPath
End Function
末級
相關:http://stackoverflow.com/a/37553538/3740093 –