Array of FileSystem Objects

  • Thread starter Thread starter timb
  • Start date Start date
T

timb

Hi,
i want to declare an array of file system watcher objects. The idea is
that my config file specifies how many directories to monitor and then i
dynamically declare the filesystemobjects and add them to an array. This
idea was so i can create a event for handling these events since i dont know
how many there are at design time and therefore cannot create the stub code.
Does anyone have any examples of such use of arrays?
 
Hi "timb",

(maybe you could write your full name here)

You can store your FileSystemWatcher Objects in an ArrayList for example.
Before adding it to the collection you should attach to the events you need,
like this:

ArrayList myWatchers = new ArrayList();
....
FileSystemWatcher newWatcher = new FileSystemWatcher();
newWatcher.Changed += new FileSystemEventHandler(OnChanged);
myWatchers.Add(newWatcher);
....
private void OnChanged(object sender, FileSystemEventArgs e)
{
// Add the code for the changed event here.
}

Hope it helps,

Neno Loje
Microsoft Student Partner
University of Hamburg
 
Back
Top