Array of FileSystem Objects

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?
 
N

Neno Loje [MSP]

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
 

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