I'm using the following code to watch a specific text file for changes:
<PermissionSet(SecurityAction.Demand, Name:="FullTrust")> _
Private Sub Run()
Dim args() As String = System.Environment.GetCommandLineArgs()
Dim watcher As New FileSystemWatcher()
watcher.Path = "P:\"
watcher.NotifyFilter = NotifyFilters.LastWrite
watcher.Filter = "SchData.txt"
AddHandler watcher.Changed, AddressOf OnChanged
watcher.EnableRaisingEvents = True
End Sub
Private Sub OnChanged(source As Object, e As FileSystemEventArgs)
UpdateSch()
End Sub
This code works when I'm watching a file on the local hard drive, but when I'm watching a file on a mapped network drive the event never fires (I don't get an error message either). I've tried inserting watcher.InternalBufferSize = 4096
just before watcher.EnableRaisingEvents = True
as was the solution in this case. I also tried using buffer sizes of 4096, 4096x4, 4096x8, 4096x10, 4096x12, 51200, and 65536 as per suggestion here.