M
Marten Van Keer
Hi;
I have two applications A and B
*** Application B listens on a network stream with a callback function:
-------------------------------------------
Public Sub WaitForData()
If Callback Is Nothing Then
Callback = New AsyncCallback(AddressOf OnDataReceived)
End If
If Not bMyRun Then
Me.objMyNetworkStream.Close()
Else
Me.m_asynResult = objMySocket.BeginReceive(objMyBytes, 0,
objMyBytes.Length, SocketFlags.None, Callback, Nothing)
End If
End Sub
----------------------------------------------------------------
Public Sub OnDataReceived(ByVal asyn As IAsyncResult)
Dim iRx As Integer = 0
Dim sLCompleteMessage As String
If Me.objMySocket.Connected Then
iRx = Me.objMySocket.EndReceive(asyn)
End If
If iRx > 0 Then
Dim numberOfBytesRead As Integer = 0
sLCompleteMessage =
Encoding.ASCII.GetString(objMyBytes).Substring(0, iRx)
RaiseEvent OnDataReceivedEvent(sLCompleteMessage)
Me.WaitForData()
End If
End Sub
-----------------------------------------
The OnDataReceived function is called when... data receives on the
networkstream. As you can see an event is raised (RaiseEvent
OnDataReceivedEvent).
Application A receives this event and does a refresh of the listview.
Now my question is the following:
The listview in application A can be refreshed by pressing F5 or by
receiving the event raised by Application B.
When the listview is being refresh manually (F5-press) the refresh is very
fast.
When the listview is being refresh automatically (by receiving event of
application B) the refresh goes very slow and the screen is being repainted
very slowly.
Is there something wrong with the OnDataReceived Sub ? Is this a threading
problem? Anyone any idea why the refresh slows down when it is triggered
externally by application B ?
Hope someone can help me out.
Regards
MVK
I have two applications A and B
*** Application B listens on a network stream with a callback function:
-------------------------------------------
Public Sub WaitForData()
If Callback Is Nothing Then
Callback = New AsyncCallback(AddressOf OnDataReceived)
End If
If Not bMyRun Then
Me.objMyNetworkStream.Close()
Else
Me.m_asynResult = objMySocket.BeginReceive(objMyBytes, 0,
objMyBytes.Length, SocketFlags.None, Callback, Nothing)
End If
End Sub
----------------------------------------------------------------
Public Sub OnDataReceived(ByVal asyn As IAsyncResult)
Dim iRx As Integer = 0
Dim sLCompleteMessage As String
If Me.objMySocket.Connected Then
iRx = Me.objMySocket.EndReceive(asyn)
End If
If iRx > 0 Then
Dim numberOfBytesRead As Integer = 0
sLCompleteMessage =
Encoding.ASCII.GetString(objMyBytes).Substring(0, iRx)
RaiseEvent OnDataReceivedEvent(sLCompleteMessage)
Me.WaitForData()
End If
End Sub
-----------------------------------------
The OnDataReceived function is called when... data receives on the
networkstream. As you can see an event is raised (RaiseEvent
OnDataReceivedEvent).
Application A receives this event and does a refresh of the listview.
Now my question is the following:
The listview in application A can be refreshed by pressing F5 or by
receiving the event raised by Application B.
When the listview is being refresh manually (F5-press) the refresh is very
fast.
When the listview is being refresh automatically (by receiving event of
application B) the refresh goes very slow and the screen is being repainted
very slowly.
Is there something wrong with the OnDataReceived Sub ? Is this a threading
problem? Anyone any idea why the refresh slows down when it is triggered
externally by application B ?
Hope someone can help me out.
Regards
MVK