Thats exactly what is happening Sven Groot, i am a new vb.net developer
what a change from vb6 hehe.
Anychance you could give me a quick example of what i have to do.
Here is where the code is happening:
THIS PART IS DONE ON THE FORM LOAD
----------------------------------------
Public Sub tryConnect()
Try
' The TcpClient is a subclass of Socket, providing higher
level
' functionality like streaming.
client = New TcpClient(strServer, PORT_NUM)
' Start an asynchronous read invoking DoRead to avoid
lagging the user
' interface.
client.GetStream.BeginRead(readBuffer, 0, READ_BUFFER_SIZE,
AddressOf DoRead, Nothing)
Catch Ex As Exception
End
End Try
If strUsername > "" Then
'When the user first enters the program
'The connect command is sent to the server
SendData("CNT" & "|" & strUsername & "|" & strNickName)
End If
End Sub
-----------------------------------------
THIS PART IS NEXT
-----------------------------------------
Public Sub DoRead(ByVal ar As IAsyncResult)
Dim BytesRead As Integer
Dim strMessage As String
Try
' Finish asynchronous read into readBuffer and return number
of bytes read.
BytesRead = client.GetStream.EndRead(ar)
If BytesRead < 1 Then
' If no bytes were read server has close. Disable input
window.
Exit Sub
End If
' Convert the byte array the message was saved into, minus
two for the
'Chr(13) and Chr(10)
strMessage = Encoding.ASCII.GetString(readBuffer, 0,
BytesRead - 2)
-----------------------------------------
THIS PART OF THIS SUB IS WHERE IT CHECKS THE COMMANDS, PASSES TO ANOTHER
SUB
-----------------------------------------
ProcessCommands(strMessage)
' Start a new asynchronous read into readBuffer.
client.GetStream.BeginRead(readBuffer, 0, READ_BUFFER_SIZE,
AddressOf DoRead, Nothing)
Catch e As Exception
MsgBox(e.Message)
End Try
End Sub
-----------------------------------------
THE FOLLOWING SUB PROCESSES THE COMMANDS
-----------------------------------------
Public Sub ProcessCommands(ByVal strMessage As String)
'TMSG|1234567890|Matt|1234567890|Message
Dim dataArray() As String
Dim lstR As ListViewItem
dataArray = Split(strMessage, Chr(124))
Select Case dataArray(0)
Case "RNICK"
'lstR = lstContacts.Items.Add(dataArray(2))
'lstR.SubItems.Add(dataArray(1))
-----------------------------------------
THIS IS THE PROBLEM AREA, IDEALLY IT WOULD BE GOOD TO HAVE THIS WHOLE
SUB RUNNING OUT OF THE THREAD SO I CAN EXECUTE CODE HERE
-----------------------------------------
Case "TMSG"
'open message window
'display received message
'Open a new window, or open window with tabs
If F4 Is Nothing Then
F4 = New frmMessage
F4.Show()
End If
Case "ERROR"
MsgBox(dataArray(1), MsgBoxStyle.Exclamation, "An Error
Has Occured")
End Select
End Sub
-----------------------------------------
I would apprechiate any further help you can give me.
Kind Regards
Matt
*** Sent via Developersdex
http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!