Problem with FileSystemWatcher/Tray Notifier App

P

Paul

Hi,

I've been developing an application in VB.NET that uses the
FileSystemWatcher and a popup notification in order to tell me when files
have been downloaded.

The FileSystemWatcher code in my project is basically the same one thats
floating all over the VB.NET sites (by Jayesh Jain). The popup notification
(called TaskbarNotifier) is a class originally by John O'Byrne written in C#
and C++ but ported to VB.NET by Patrick Vanden Driessche. It was downloaded
from codeproject.com.

Both of these elements (FileSystemWatcher and TaskBarNotifier) work
perfectly on the own but I experienced problems when I tried incorporating
and combining them in my own project.

Basically, the FileSystemWatcher will detect files created, changed, deleted
etc and the TaskBarNotifier will display popups as it should. The problem
comes when I create a file (by means of downloading it or by just copying it
to the 'watched' folder directly). I've coded it so the TaskBarNotifier
should popup with name of the file created/downloaded then disappear after 3
seconds. It should, but doesn't. I can't understand why the same code will
not run when used under a different procedure.

I would of prefered to paste the code here in the hope people willing and
able to help can paste it directly into their own VB.NET environment but the
project contains bitmaps (as Embedded Resources) for the skins of the popups
and they need to be included when compiling/testing the app otherwise it
won't compile. So for this reason I've posted the project on my website for
download.

Homepage: http://www.geocities.com/toffee_paul/fun_d_mental.html
Direct Link: http://www.geocities.com/toffee_paul/vbnetproj.zip

When compiled and the form is displayed, click 'Test just the Popup' and the
popup will appear as it should. Now change the 'watch folder' to a valid
folder and copy a file to this folder. The app will detect the newly
created file (as proven in the 'content' textbox) but the popup will fail to
appear. Very strange problem.

Any help is very much appreciated,
Thanks
Paul
 
H

Herfried K. Wagner [MVP]

Paul said:
The FileSystemWatcher code in my project is basically the same one thats
floating all over the VB.NET sites (by Jayesh Jain). The popup
notification (called TaskbarNotifier) is a class originally by John
O'Byrne written in C# and C++ but ported to VB.NET by Patrick Vanden
Driessche. It was downloaded from codeproject.com.

Both of these elements (FileSystemWatcher and TaskBarNotifier) work
perfectly on the own but I experienced problems when I tried incorporating
and combining them in my own project.

Make sure that the 'FileSystemWatcher''s 'SynchronizingObject' is set to
your form. Otherwise your event handlers are executed on a thread of the
thread pool and thus invoking will be required to access Windows Forms
elements running in the application's main UI thread.
 
P

Paul

Brilliant, thanks Herfried!

I added the following line to the Load event of my form....

WatchFolder.SynchronizingObject = Me

And all works perfectly now.
Thanks again.
Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top