FilesySystemWatcher over network

时间:2015-05-28 18:37:26

标签: vb.net networking buffer filesystemwatcher

我正在使用以下代码观看特定文本文件的更改:

<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

当我在本地硬盘上观看文件时,此代码有效,但当我在映射的网络驱动器上观看文件时,事件永远不会触发(我也没有收到错误消息)。我尝试在watcher.InternalBufferSize = 4096之前插入watcher.EnableRaisingEvents = True,就像this case中的解决方案一样。我还尝试使用4096,4096x4,4096x8,4096x10,4096x12,51200和65536的缓冲区大小here

1 个答案:

答案 0 :(得分:0)

有其他SO问题的说明,这可能是权限问题。确保运行应用程序的用户对正在监视的目录具有适当的权限。

FileSystemWatcher to watch UNC path

尝试以管理员身份运行您的应用程序(如果您在该上下文中运行,则运行Visual Studio)。