HELP! - FileSystemWatcher Problems

G

Guest

Hello Everyone and thanks for your help in advance. I have been battling a
problem for nearly a month with the FileSystemWatcher component. Basically,
what I am trying to do it to monitor three separate folders on a Windows 2000
server for activity. In my code, I have set up three separate subroutines:

FaxWatch()
ReportWatch()
ScheduleWatch()

Each of the subroutines creates a new instance of the FileSystemWatcher.
However, I am running into a number of issues. First and most problematic is
that when I create two instances of the component, it seems to work, but a
third one stops all monitoring entirely (for example, calling the
ScheduleWatch() routine). Additionally, some of the files written to the
directory are somewhat large, and I need to figure out a way to wait for the
file to be completely written before taking action. I have tried LastWrite
and LastModified filters, but they don't seem to completely solve the
problem. Finally, there is the documented issue of multiple events being
fired from one event, but I think I can work around this issue if I can get
the rest working properly. The FileSystemWatcher really looks like a useful
tool, but only if it works correctly. Any help on this issue is greatly
appreciated. Thanks.
 
F

Frankie

kmcnet,
I had this problem, and the way that I worked around the problem was
creating two separate arraylists, one to monitor the events, the other was
used to process the items. When the event came in, I updated the arraylist
using the filename as the key. I used a timer to set a delay on the
processing and once things stabilized, just a few seconds, I moved my
"monitored" items into my queue and processed them. This may not be the best
way of doing things, actually, I don't really like the way I did it, but, it
worked. You may be able to tell if the file is finished by opening the file
exclusively, if you can then you know that something still has a handle on
it and suspend your processing. Remember to set the NotifyFilter property
to only those events you're interested in. hth
 
G

Guest

Well, it sort of helps, but I really can't figure out why the third instance
of the FileSystemWatcher stops the processing altogether. I had thought
about buffer size, but it is only hanlding about 5 files per hour, so I
really don't think that is the case. Is there a maximum number of watchers
than can be instantiated?
 

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