FileWatcher check on startup?

  • Thread starter Thread starter tshad
  • Start date Start date
T

tshad

Is there some way to have the fileWatcher to initially check the folder to
see if there is anything in it (based on the filters)?

If I reboot the machine, for example, and it starts up the service - I would
like it to look at the folder initially. The reason being that I may bring
the system down and at that point the files may be written to the target
directory. When I bring it back up again and the service starts, it won't
see that the files were added to the folder while it was down and will never
see those files.

Thanks,

Tom
 
tshad said:
Is there some way to have the fileWatcher to initially check the folder to
see if there is anything in it (based on the filters)?

If I reboot the machine, for example, and it starts up the service - I
would like it to look at the folder initially. The reason being that I
may bring the system down and at that point the files may be written to
the target directory. When I bring it back up again and the service
starts, it won't see that the files were added to the folder while it was
down and will never see those files.

Thanks,

Tom
Immediately after setting up the file watcher, do a manual check via
File.Exists() or Directory.GetFiles() and handle anything you find at that
point.

Mike.
 
Tom,

No, there isn't, but that doesn't mean that you can't scan the folder
yourself before you start the file watcher. Because you might run into a
situation where a file might be changed while the file watcher operates, you
might want to block the file watchers events from executing before you are
done scanning the directory initially.
 
Michael D. Ober said:
Immediately after setting up the file watcher, do a manual check via
File.Exists() or Directory.GetFiles() and handle anything you find at that
point.

I did Directory.GetFiles() and it worked fine.

Unfortunately, it doesn't seem to allow multiple filters, so I just did it 3
times as I needed to see files that started with "IN*", "GL*" and "TX*"
only.

Thanks,

Tom
 
Nicholas Paldino said:
Tom,

No, there isn't, but that doesn't mean that you can't scan the folder
yourself before you start the file watcher. Because you might run into a
situation where a file might be changed while the file watcher operates,
you might want to block the file watchers events from executing before you
are done scanning the directory initially.
Actually, you're right.

I actually did the manual scan (as I mentioned in response to Michael)
before starting up FileWatcher class. And there will be various times I may
want to do a manual scan as well.

Thanks,

Tom
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

tshad said:
Is there some way to have the fileWatcher to initially check the folder
to see if there is anything in it (based on the filters)?

If I reboot the machine, for example, and it starts up the service - I
would like it to look at the folder initially. The reason being that I
may bring the system down and at that point the files may be written to
the target directory. When I bring it back up again and the service
starts, it won't see that the files were added to the folder while it was
down and will never see those files.

Thanks,

Tom
 
tshad said:
Actually, you're right.

I actually did the manual scan (as I mentioned in response to Michael)
before starting up FileWatcher class. And there will be various times I
may want to do a manual scan as well.

I have a program that runs on a server using FSW. What I discovered is that
on slower hardware the dotNET 2.0 FSW can miss file events sometimes, so I
acutally put an explicit scan in every 15 minutes. Both the FSW processing
events (change, create, etc.) and my scan call the same routine to process
the files. On fast hardware, my explicit scans never seem to catch
anything.

Mike.
Thanks,

Tom
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

tshad said:
Is there some way to have the fileWatcher to initially check the folder
to see if there is anything in it (based on the filters)?

If I reboot the machine, for example, and it starts up the service - I
would like it to look at the folder initially. The reason being that I
may bring the system down and at that point the files may be written to
the target directory. When I bring it back up again and the service
starts, it won't see that the files were added to the folder while it
was down and will never see those files.

Thanks,

Tom
 
Michael D. Ober said:
I have a program that runs on a server using FSW. What I discovered is
that on slower hardware the dotNET 2.0 FSW can miss file events sometimes,
so I acutally put an explicit scan in every 15 minutes. Both the FSW
processing events (change, create, etc.) and my scan call the same routine
to process the files. On fast hardware, my explicit scans never seem to
catch anything.

That would seem to imply that very soon (as the hardware gets faster), the
FileWatcher class will be useless. You may as well just set up a timer task
that just runs every hour or so.

Thanks,

Tom
Mike.
Thanks,

Tom
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Is there some way to have the fileWatcher to initially check the folder
to see if there is anything in it (based on the filters)?

If I reboot the machine, for example, and it starts up the service - I
would like it to look at the folder initially. The reason being that I
may bring the system down and at that point the files may be written to
the target directory. When I bring it back up again and the service
starts, it won't see that the files were added to the folder while it
was down and will never see those files.

Thanks,

Tom
 
tshad said:
That would seem to imply that very soon (as the hardware gets faster), the
FileWatcher class will be useless. You may as well just set up a timer
task that just runs every hour or so.

That's backwards... Michael said the FileWatcher works better with newer
hardware.
 
Back
Top