Search code examples
vb.netfilesystemwatcherrdp

VB .NET FileSystemWatcher does not fire event on rdp connection


Hy all, I am newbie on this forum and I am italian. First of all I'm sorry for language mistakes; also, reading replies should be after a lot of hours due to different country time.

Configuration: VB .NET 2008 PRO and VB .NET 2008 EXpress

My 2 desktop PC: 1 is WinXP SP3 and 1 is Win7 SP1

Server: Windows 2008 R2 Enterprise

.NET framework: 3.5 SP1

I have developed a WinForms application that runs on server 2008; in the app I use the File System Watcher (FSW) component to receive notification on file deletion for a folder that is on connected PC. Connection is by Remote Desktop (RDP). When users, using the app, deletes a file on this folder (and the app do this work and file on PC is really deleted) I need FSW notify the event. I don't have any error in code, simply FSW doesn't fire the event and so I don't receive any notification from PC. Code for FSW (pasted below) isn't executed. lvwDocFiles is a ListView.

Private Sub fswFiles_Deleted(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles fswFiles.Deleted

    Try
        lvwDocFiles.Items.RemoveByKey(e.FullPath)
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try

End Sub

FSW is started and runs when users make deletion. Above code runs when users delete a file on local folder (folder on server) so in this case FSW correctly raise the event.

I have seen already the following post (asked 6 years ago):

FileSystemWatcher Fails to access network drive

but is in C# and is different from my situation.

In my mind I think for possible reasons of this:

  1. On PC a specific service must be running? For example I tried to starts Alert service but nothing change
  2. Permissions? But the file has been deleted (the DEL command starts from application on server and correctly arrives on PC)
  3. Notification starts from PC but do not pass through the RDP connection?
  4. Notification does not start on PC? I don't know how to investigate on this and previous point (I need a specific program to do this?)

Any suggestions will be highly appreciated.

Thanks to all
Stefano


Solution

  • I have solved my problem in this way: - Deleted FSW from the project - Added 2 custom events, first (FileChangeEvent) will be raised from child form when a file delete occurs in child and communicate this to parent form via a custom eventargs; second (ChildUpdateList) will be raised by parent to communicate to all active childs (all instances of the same form) that one child (not always the same in which delete occurs) must update the list of file in own listview. This is a simple and good solution that controls also the file delete on remote folders (FSW doesn't work on this situation).

    Thanks to all that gives me comments and special thanks to Colin Angus MacKay Blog Passing Data Between Forms in which I have found a trace to solve and to Diego Cattaruzza (MVP) Visual-Basic.it (sorry it is in italian) that helps me to greatly simplify the Colin solution.

    Stefano