2

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

Community
  • 1
  • 1
Steve55
  • 31
  • 6
  • Can you sum your 3 pages into a short, relevant information on what goes wrong. Why are you rapping about a listview while your problem is with a filesystemwatcher. In all the lines you typed you failed to provide detailed on error during execution. On what line of code does it fail, and what is the error message. Also take these lines in to a fresh new project without any other code, to prove the problem is now with something else... – Dennis May 01 '16 at 09:10
  • Hy Lectere, thanks for your comment. I have rewritten the post. I hope now is much clear. I don't have error in code so I cannot post anything. Simply FSW seems not work as Microsoft declares on MSDN (...works also on remote computers...) – Steve55 May 01 '16 at 11:19
  • FSW has some shortcomings. Does it report any errors through its `Error` event? Also, your event-handling code must be as fast as possible or you may miss notifications; but `MessageBox.Show()` is blocking. Is your network share high-traffic? – Norman May 01 '16 at 12:13
  • Hy Norman, as per your comment I have added the FSW error event and yes I get an error with its sender is FSW. the message was **"Too many changes at once in directory:\\tsclient\c\temp"**. Also the message.show fires only in case of error and I had put it in FSW_Deleted for debug purpose. The network during normal office hour can have high traffic but now I have error and traffic is almost zero – Steve55 May 01 '16 at 13:18
  • but the change in remote folder is only one and it is the file delete (that occurs correctly). – Steve55 May 01 '16 at 13:30
  • I'm confused by your last comment. Is \\tsclient\c\temp the remote folder? Anyway, I think the error message is self-explanatory: FSW gets overwhelmed and starts dropping events. You should check that you increased InternalBufferSize and made the filter as specific as possible, esp. not recursive if not necessary. – Norman May 01 '16 at 17:09
  • Sorry Norman. The **\\tsclient\c\temp** is the remote folder in which file delete occurs. I have already increased **InternalBufferSize** to the max 64K but without any changes and Filter is **All Files** because I don't know this when I start FSW. Error raise again. I have found over the internet others with the same problem and someone sets a solution with a modified FSW like [link](https://petermeinl.wordpress.com/2015/05/18/tamed-filesystemwatcher/) . Next days I will try this approach and results will be posted. Thanks a lot for your comments. – Steve55 May 01 '16 at 18:11
  • Unfortunetly solution by Peter Meinl (as per link in above comment) is not applicable to me because it has been developed in VS2015 on framework 4.5. I use VS2008 and framework 3.5. – Steve55 May 02 '16 at 08:36
  • I've had a look around, and I can't see any mention of remote file system events being transmitted over rdp I'm afraid – David Wilson May 02 '16 at 09:59
  • Thanks David. In fact, the title of the post does not reflect properly the problem that became clear during the various comments. FSW triggers events also via RDP but these are not detected by the application because the internal buffer overflows with the message **Too many changes at once in directory** – Steve55 May 02 '16 at 13:36
  • Being on .NET 3.5, you could roll your own async event processing. Just add a queue, protect it with a lock, make the FSW signal an AutoResetEvent after adding an event to the queue, and add another BackgroundWorker that (in an endless loop) waits on the AutoResetEvent before extracting the events from the queue. That BackgroundWorker then uses `ReportProgress(0, userState:=event)` to emulate the FSW's Created/Changed/etc. events. – Norman May 05 '16 at 11:41
  • Thanks Norman for your comment. Your approach is new for me so I must analyze, understand well and next coding. I think it can be my solution. – Steve55 May 05 '16 at 15:10

1 Answers1

1

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

Steve55
  • 31
  • 6