V
Vemund Halvorsen
Hi,
Im having some trouble getting Addhandler to work. Using withevents
everything is working fine. But with AddHandler I get no callback.
The code below works fin if I declare _tcp as a private class member (etc.
Dim WithEvents mTcp as New MyTCP). Classes/modules; module Main, class
MyCtrl and class MyTcp.
Any tips why using AddHandler dont work?
/Vemund
Adding handler (from MyCtrl):
---
Dim _tcp As New MyTcp
_tcp.Init(ip, port)
AddHandler _tcp.OnDataArrival, AddressOf TcpHandler
---
Handler (from MyCtrl):
---
Public Sub TcpHandler(ByVal data As String)
RaiseEvent OnDataArrival(data)
End Sub
---
Rasing event (from MyTcp):
---
Public Sub ReadHandler(ByVal asyncResult As IAsyncResult)
Dim data As String = String.Empty
Dim bytes As Int32 = mNetStream.EndRead(asyncResult)
data = Encoding.ASCII.GetString(mReadbuffer, 0, bytes)
Console.WriteLine("Received: {0}", Data)
RaiseEvent OnDataArrival(data)
Dim result As IAsyncResult = mNetStream.BeginRead(mReadbuffer, 0,
mReadbuffer.Length, ReadCallback, Nothing)
End Sub
---
Im having some trouble getting Addhandler to work. Using withevents
everything is working fine. But with AddHandler I get no callback.
The code below works fin if I declare _tcp as a private class member (etc.
Dim WithEvents mTcp as New MyTCP). Classes/modules; module Main, class
MyCtrl and class MyTcp.
Any tips why using AddHandler dont work?
/Vemund
Adding handler (from MyCtrl):
---
Dim _tcp As New MyTcp
_tcp.Init(ip, port)
AddHandler _tcp.OnDataArrival, AddressOf TcpHandler
---
Handler (from MyCtrl):
---
Public Sub TcpHandler(ByVal data As String)
RaiseEvent OnDataArrival(data)
End Sub
---
Rasing event (from MyTcp):
---
Public Sub ReadHandler(ByVal asyncResult As IAsyncResult)
Dim data As String = String.Empty
Dim bytes As Int32 = mNetStream.EndRead(asyncResult)
data = Encoding.ASCII.GetString(mReadbuffer, 0, bytes)
Console.WriteLine("Received: {0}", Data)
RaiseEvent OnDataArrival(data)
Dim result As IAsyncResult = mNetStream.BeginRead(mReadbuffer, 0,
mReadbuffer.Length, ReadCallback, Nothing)
End Sub
---