0

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.

The Blue Dog
  • 2,475
  • 3
  • 19
  • 25
Mr. Phil
  • 61
  • 1
  • 2
  • 9

1 Answers1

0

There are notes on other SO questions that this could be a permissions issue. Make sure the user running the application has proper permissions over the directory being watched.

FileSystemWatcher to watch UNC path

Try to run your application (or Visual Studio if you are running within that context) as an administrator.

Community
  • 1
  • 1
nbushnell
  • 1,724
  • 1
  • 14
  • 14
  • This program is running two (and later more) computers looking at the same file. Both of them can read the file when it loads on startup. They can also both write to the file. Because of this I don't think it is a permissions issue. – Mr. Phil May 29 '15 at 00:08