View Single Post
 
Old 09-19-2013, 07:47 AM
skip0464's Avatar
skip0464 skip0464 is offline
Centurion
 
Join Date: Dec 2003
Location: New Jersey
Posts: 105
Default Socket Program getting stack exception

i have a program with 2 threads. thread1 is waiting for data over ethernet using sockets. the data is received and i invoke a routine to update a field on the screen. this works great for 2,750 times then i get a stack exception for recursive routines. basically my process gets the data, updates the screen and calls a routine that calls my "waiting for data" routine.

Now i tried to slow things down by putting the thread to sleep for 100ms however i received the same error after about 2000 times processed.

the error happens on line me.invoke(mi)
thread_start just calls waitfordata

Code:
   Private Sub waitfordata()
        Try
            Dim serverStream As NetworkStream = clientSocket.GetStream()
            Dim bytes(clientSocket.ReceiveBufferSize) As Byte
            serverStream.Read(bytes, 0, CInt(clientSocket.ReceiveBufferSize))
            Dim returndata As String = Encoding.ASCII.GetString(bytes)
            rtdata = returndata.ToString
            Dim mi As MethodInvoker = AddressOf UpdateFormText
            Me.Invoke(mi)
            Call thread_start()
        Catch ex As Exception
            MessageBox.Show(Err.Description)
        End Try
    End Sub

Last edited by passel; 09-19-2013 at 08:19 AM.
Reply With Quote