Event problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I use the following class in my current program

Public Class Tes
Public Event EventOne (ByVal obj as Object, ByVal message as String

[...

Public Sub ReceiveCallback(ByVal ar As IAsyncResult) 'This is acutally a handler for the async use of socket
[...] 'do usual stuf
MsgBox("about to raise event"
RaiseEvent EventOne(Me, message) 'message is a string, that consists of received dat
[...
End Su

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
That's how I use the new class
Public WithEvents d as New Test 'definition in clas
[...
AddHandler d.EventOne, AddressOf ReceiveHandler 'This is in the Form_Load handle

Public Sub ReceiveHandler(ByVal obj As Object, ByVal message As String) Handles d.ReceiveFinishe
MsgBox(message
End Su

Now, the problem is, that although the event is only raised once (and so the Msgbox "about to raise event" does only appear once) the ReceiveHandler is called twice. Can anyone tell me why

Thanks a lo
Gordon
 
You're registering the event handler twice

Since you declared d using the WithEvents keyword, you can skip the call to AddHandler. The event will be mapped correctly because you have 'Handles d.EventOne' at the end of you method declaration

Charli
 
Back
Top