0

I've this scenario: a user of my service application wants to configure in a xml configuration file a list of n paths. At startup time I want to create n filesystemwatcher with their eventhandler.

How to do this?

Is really simple in vs to create FileSystemWatcher, but how to do this when I don't know how many?

Thanks!

ff8mania
  • 1,553
  • 3
  • 19
  • 28
  • what was the end solution you went with? – zaitsman Feb 15 '14 at 08:17
  • You can check out this link: http://www.c-sharpcorner.com/UploadFile/mokhtarb2005/FSWatcherMB12052005063103AM/FSWatcherMB.aspx. There is also a CodeProject article about [Using FileSystemWatcher to monitor multiple directories](http://www.codeproject.com/Articles/271669/Using-FileSystemWatcher-to-monitor-multiple-direct). Also, check out the related post: https://stackoverflow.com/questions/2716401/monitor-multiple-folders-using-filesystemwatcher. – Igor Ševo Oct 15 '13 at 10:03

1 Answers1

1

Creating FSW instance for each path would be Expensive, i would suggest to go with root directory. eg. C:\ or D:\, then filter out the path which is not required.

For example,

Create FSW for C:\

if you want to monitor only C:\Windows\System32, ignore events other than System32 path. this way you can do what you expect...

Rajesh Subramanian
  • 6,400
  • 5
  • 29
  • 42
  • Hi, I thought at a solution like this, but wouldn't be more expensive in this way, wasting (in my case) the 99% of the events? In my situation the "n" is usually 3 or 4, no more – ff8mania Oct 15 '13 at 10:00
  • in this case, you can have a Lazy List in memory of size predefined and create objects for the list on demand – Rajesh Subramanian Oct 15 '13 at 10:07