dimanche 10 mai 2015

Event raised in the constructor are not received in parent class but received in own class

I encountered this situation and can't figure a workaround:

Class NetworkConnection
   Sub New 
          RaiseEvent networkAvailable(getNetwork())
   End Sub

   Event networkAvailable(available as Boolean)

   Sub innerHandler Handles networkAvailable
            'this sub captures the event ok
   End sub

   Function getNetwork() As Boolean
         'get network status
         Return status
   End Function
End Class

Class myServer
    WithEvents my_connection As NetworkConnection

    Sub New
         my_connection = New NetworkConnection
    End Sub

    Sub CaptureConnectionEvent (state As Boolean) handles my_connection.networkAvailable
          'this event is never captured when is raised in class constructor
          'it is captured however if it's triggered later with a button click for example
    End Sub
End Class

I have no ideea why this happens? What is the logic of Visual Basic to send event raised in the constructor only to the raising class handlers and not to the parent class handlers?

Also if you guys have a workaround ideea it would be very appreciated (without kinky solutions like wait 10 seconds or make the user click a button) :)

Thank you.

Aucun commentaire:

Enregistrer un commentaire