By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,857 Members | 1,813 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,857 IT Pros & Developers. It's quick & easy.

HELP! - FileSystemWatcher Problems

P: n/a
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.
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

"kmcnet" <km****@discussions.microsoft.com> wrote in message
news:A5**********************************@microsof t.com...
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.

Nov 21 '05 #2

P: n/a
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?

"Frankie" wrote:
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

"kmcnet" <km****@discussions.microsoft.com> wrote in message
news:A5**********************************@microsof t.com...
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.


Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.