Hello, I'm having issues trying to get file system watchers working properly, I'm not sure whats not right here, I want to use multiple, but I can't even get one of them to fire on an event...
simple form with a listbox for folders to watch and a listbox to list changes detected and a command button to launch watchers.
Code:Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load lstFolders.Items.Add("C:\temp\1") lstFolders.Items.Add("C:\temp\2") lstFolders.Items.Add("C:\temp\3") End Sub Private Sub cmdWatch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdWatch.Click For i As Integer = 0 To lstFolders.Items.Count - 1 'MsgBox(Me.lstFolders.Items(i)) fnWatchFolder(lstFolders.Items(i), "*.txt") Next End Sub Public Function fnWatchFolder(ByVal strFolderToWatch As String, ByVal strFileExtension As String) As Boolean ' Get the path to the directory we will watch. ' Make the FileSystemWatcher. Dim FileWatcher = New FileSystemWatcher(strFolderToWatch, strFileExtension) FileWatcher.NotifyFilter = NotifyFilters.FileName ' Or NotifyFilters.FileName FileWatcher.EnableRaisingEvents = True AddHandler FileWatcher.Changed, AddressOf OnChanged fnWatchFolder = True End Function Public Sub OnChanged(ByVal source As Object, ByVal e As FileSystemEventArgs) MsgBox("change occured") lstChanges.Items.Add(e.FullPath & " : " & e.ChangeType.ToString("G")) End Sub





Reply With Quote