FileSystemWatcher name by sender 
Author Message
 FileSystemWatcher name by sender

I have created several FileSystemWatchers with different monitor paths
and added event handlers with the same addressof sub. My goal is to
parse all the events through the same event handler and call different
ssubs based on which FSW raised the event. Is there a way to get the
name of the FSW that raised the event from the sender object or any
other way? Ref:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

        FSW1.Path = Path1
        FSW2.Path = Path2

        FSW1.EnableRaisingEvents = True
        FSW2.EnableRaisingEvents = True

        AddHandler FSW1.Created, AddressOf FSW_OnCreated
        AddHandler FSW2.Created, AddressOf FSW_OnCreated

End Sub

Private Sub FSWSuntrustReports_OnCreated(ByVal sender As Object, ByVal
e As System.IO.FileSystemEventArgs)

        Select Case sender.????
                Case FSW1
                        sub1
                Case FSW2
                        sub2
        end select

End Sub

I have unsuccessfully several sender methods and properties as well as
ctype of FSW. In theory I could have 40 FSW and don't want that many
event handler subs.

Thanks in advance
Shane Miller



Mon, 01 Aug 2005 06:57:35 GMT  
 FileSystemWatcher name by sender

Quote:
> I have created several FileSystemWatchers with different monitor
> paths and added event handlers with the same addressof sub. My
> goal is to parse all the events through the same event handler
> and call different ssubs based on which FSW raised the event. Is
> there a way to get the name of the FSW that raised the event
> from the sender object or any other way? Ref:

> Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load

>         FSW1.Path = Path1
>         FSW2.Path = Path2

>         FSW1.EnableRaisingEvents = True
>         FSW2.EnableRaisingEvents = True

>         AddHandler FSW1.Created, AddressOf FSW_OnCreated
>         AddHandler FSW2.Created, AddressOf FSW_OnCreated

> End Sub

> Private Sub FSWSuntrustReports_OnCreated(ByVal sender As Object,
> ByVal e As System.IO.FileSystemEventArgs)

> Select Case sender.????
> Case FSW1
> sub1
> Case FSW2
> sub2
> end select

> End Sub

> I have unsuccessfully several sender methods and properties as
> well as ctype of FSW. In theory I could have 40 FSW and don't
> want that many event handler subs.

If sender Is FSW1 Then
    sub1
Elseif sender Is FSW2 hen
    sub2
End If

But, why not create 40 event handlers? Now you have 40 subs (sub1-sub40)
*and* you have to write 40 "if sender is.." statements, so I don't see an
improvement.

Armin



Mon, 01 Aug 2005 07:07:41 GMT  
 FileSystemWatcher name by sender
Sender doesn't yield the name of control that raised the event. I
wouldn't use 'if..then', select case is cleaner. I create the FSWs and
the directories they watch dynamically from a database. I can pass the
name of the calling FSW into another select to determine the
characteristics of the processing for that particular file/direcory. I
can't code the event handler subs dynamically. The goal is to make the
app as modular as possible using normalized data.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Mon, 01 Aug 2005 08:04:11 GMT  
 FileSystemWatcher name by sender

Quote:
> Sender doesn't yield the name of control that raised the event. I
> wouldn't use 'if..then', select case is cleaner. I create the
> FSWs and the directories they watch dynamically from a database.
> I can pass the name of the calling FSW into another select to
> determine the characteristics of the processing for that
> particular file/direcory. I can't code the event handler subs
> dynamically. The goal is to make the app as modular as possible
> using normalized data.

You can't use select case with the reference comparing Is operator this way.
That's why I used If..then. But you can try

Select Case True
Case sender Is FSW1
    '
case sender Is FSW2
    '
end selct

I still don't understand your problem exactly. Is it that, at
design time, you don't know the number of FSWs you're gonna create at
runtime? In this case you can not declare a certain number of FSW variables
at design time. You need a different way to identify FSWs. Unfortunatelly I
don't know how *you* would identify them because I don't know the criteria
that decides which sub has to be called. You could derive a new class from
Filesystemwatcher and add an identifying property, like an ID or a name. In
the event procedure you could distinguish between them by the ID. Type
casting is required:

Select Case directcast(sender, ClassDerivedFromFSW).id
case 17
    sub1
case 4711
    sub2
end select

You could also implement a Type property (Enum) to group certain types of
FSWs and use it as the selection criteria.

Does this help?

Armin



Mon, 01 Aug 2005 18:58:49 GMT  
 FileSystemWatcher name by sender
I have directories assigned to companies for incoming and outgoing file
transfers. Companies can have multiple incoming or outgoing directories.
At application start I query a master table and create FSWs for each
company entry. ie. CompAIn, CompBIn, CompAOut, CompAAOut. The event
handler would process the files based on the name given to the component
at run time. CompAIn needs encryption, archiving and notification;
CompAOut needs transport and notification, etc. I could assign a unique
identifier to each FSW and use that identifier to handle the file based
on the identifiers relation to normalized tables in the database.

Like "Select * from tblEncryption, tblTranport, tblArchiving,
tblNotification where UniqueID='" & sender.uniqueid & "'".

It doesn't have to be 'select case'. I just need to be able to assign a
unique id to each control at application start that I can retrieve when
the event handler fires.
I have thought about a new class from the FSW and add an identifying
property, but didn't want to if I could do it with the base component.
Like command buttons have a name property that isn't present on a FSW.
This may be what I have to do. Thanks,  

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Tue, 02 Aug 2005 00:35:52 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. sender name and recipient name?

2. Get Name Of FileSystemWatcher

3. Get sender name from a read receipt

4. How can i change the Sender Name??

5. get sender name and emailadress ?

6. Changing the sender name from Outlook VBA

7. Specifying sender name

8. Getting the name of the sender

9. How to change sender's name

10. Cant resolve sender name to email address

11. Changing the Sender Name

 

 
Powered by phpBB® Forum Software