Multiple FileSystemWatcher

stustarz

Well-known member
Joined
Jan 10, 2003
Messages
246
Location
Earth
I have an application which creates multiple instances of the FileSystemWatcher. There is a Start Button which starts the monitoring and a Stop button which i plan to stop them :)

So far i am going down the path of creating an array of FSWs:

Code:
Dim objWatchFolder(3) As FileSystemWatcher

For i As Integer = 0 To 2
objWatchFolder(i) = New System.IO.FileSystemWatcher
Next

The rest of the code to set the parameters for the FSW is here

Now, this works fine, all the directories are being monitored and events firing no problem.

But, how do i close them all in a seperate button click event? I think i am missing something about working with multiple object / class instances

Cheers

Stu
 
Close them as have them stop monitoring? if so, just use the same loop and mark their enable property to False. not sure if this is what you are wanting.
 
Yeah! i tried that but it wouldnt work because the object reference wasnt set to an instance of object - or so .net told me :)

I got around it now though, simply created the watcher in a seperate class and everytime i opened a new instance i would add it into an arraylist - then i just need to loop through the arraylist to close them all!

Thanks anyway
 
Back
Top