Addhandler problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cwthong
    New Member
    • Jun 2010
    • 2

    Addhandler problem

    Hi,

    I've this procedure

    Code:
    Private Sub ClientSocket_WriteCompleted(ByVal sender As Object, ByVal e As AsyncCompletedEventArgs)
    ...
    End Sub
    and I need to addhandler for it
    Code:
    Private Sub buttonConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonConnect.Click
    ........        
    ClientSocket = New SimpleClientTcpSocket()
    AddHandler ClientSocket.WriteCompleted, AddressOf ClientSocket_WriteCompleted
    End Sub


    but always get an error for the AddHandler line
    Error 1 Method 'Private Sub ClientSocket_Wr iteCompleted(se nder As Object, e As System.Componen tModel.AsyncCom pletedEventArgs )' does not have a signature compatible with delegate 'Delegate Sub Action(Of System.Componen tModel.AsyncCom pletedEventArgs )(obj As System.Componen tModel.AsyncCom pletedEventArgs )'.

    It will only work if i change the procedure to
    Code:
    Private Sub ClientSocket_WriteCompleted(ByVal e As AsyncCompletedEventArgs)
    ...
    End Sub

    Can anyone tell me what is wrong with the original code and how to solve it instead of removing the sender As Object in the procedure.
    Thanks.
  • Aimee Bailey
    Recognized Expert New Member
    • Apr 2010
    • 197

    #2
    Originally posted by cwthong
    Hi,

    I've this procedure

    Code:
    Private Sub ClientSocket_WriteCompleted(ByVal sender As Object, ByVal e As AsyncCompletedEventArgs)
    ...
    End Sub
    and I need to addhandler for it
    Code:
    Private Sub buttonConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonConnect.Click
    ........        
    ClientSocket = New SimpleClientTcpSocket()
    AddHandler ClientSocket.WriteCompleted, AddressOf ClientSocket_WriteCompleted
    End Sub


    but always get an error for the AddHandler line
    Error 1 Method 'Private Sub ClientSocket_Wr iteCompleted(se nder As Object, e As System.Componen tModel.AsyncCom pletedEventArgs )' does not have a signature compatible with delegate 'Delegate Sub Action(Of System.Componen tModel.AsyncCom pletedEventArgs )(obj As System.Componen tModel.AsyncCom pletedEventArgs )'.

    It will only work if i change the procedure to
    Code:
    Private Sub ClientSocket_WriteCompleted(ByVal e As AsyncCompletedEventArgs)
    ...
    End Sub

    Can anyone tell me what is wrong with the original code and how to solve it instead of removing the sender As Object in the procedure.
    Thanks.
    surely you dont need the sender object, as sender is ClientSocket ?

    Comment

    • cwthong
      New Member
      • Jun 2010
      • 2

      #3
      Originally posted by AmzBee
      surely you dont need the sender object, as sender is ClientSocket ?
      Yes, I need it. However the problem can be solved easily by upgrading to vs2010

      Comment

      Working...