Getting list of dynamically created objects.

M

Mike Quernemoen

Hello,
I've got an application which creates a filesystemwatcher for each record in
a datatable as shown in attached code. I'm wondering how I would get list
of these dynamically created objects from a different function.
Thanks,
Mike

This is my how I create a filesystemwatcher for each record.
Dim fsw As FileSystemWatcher

For Each dr In dt.Rows

If dr("INVALID") <> True Then

fsw = createfsw(dr.Item("repdir"), dr("INCLUDESUBDIRS"))

End If

Next



Private Function createfsw(ByVal repdir As String, Optional ByVal
INCLUDESUBS As Boolean = False) As FileSystemWatcher

Dim fsw As New FileSystemWatcher()

fsw.Path = repdir

fsw.EnableRaisingEvents = True

fsw.IncludeSubdirectories = INCLUDESUBS

fsw.SynchronizingObject = Me

AddHandler fsw.Created, AddressOf FSW_Created

AddHandler fsw.Changed, AddressOf FSW_Created

AddHandler fsw.Deleted, AddressOf FSW_Deleted

AddHandler fsw.Renamed, AddressOf FSW_Renamed

Return fsw




End Function
 
M

Max

Two solutions:
1. Add some collection (CollectionBase) to your and each time you create a
fsw add it to collection.

2. Create YourFileSystemWatcher class derived from FileSystemWatcher.
Add a static member variable of type collection to it.
In the constructor - Add "me" to the collection.
In the destructor - remove.
Add a public static function to obtain this collection or it's elements.
 

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