Results 1 to 4 of 4

Thread: TCPListener maybe thread issue??

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2001
    Posts
    33

    TCPListener maybe thread issue??

    I have a program that has 2 forms. In one form I have a TCPListener running in the thread. This part works fine and receives the data like it should.
    When the data is received I am trying to place what is received in a textbox on another form.
    On the other form the routine that places the text in the textbox I have tried checking to see if an invoke is needed and it always returns false. So I have a statement like this
    Code:
     Public Sub ImportExternalADIFStringInvoke(ByVal aStr As String)
            Try
                If InvokeRequired Then
                    Dim d As New ImportExternalADIFStringDelegate(AddressOf ImportExternalADIFString)
                    BeginInvoke(d, [aStr])
                Else
                    ImportExternalADIFString(aStr)
                End If
            Catch e As Exception
                Debug.Print(e.Message)
            End Try
        End Sub
    
    Public Sub ImportExternalADIFString(ByVal aStr As String)
            Try
    
                Debug.Print(aStr)
                Loggedvia.Text = ""
                Log.Text = ""
    
                Log.Text = aStr
    The debug statement prints out the contents of aStr but the log window does not display any text. If I break the routine after this point and I hold the mouse over Log.text it shows that the contents contain what aStr holds but the text is not visible in the textbox. I have double checked all of the settings for the textbox and if I enter text in the controls setup it shows in the window.

    This is driving me nuts as to why the text does not show...
    I have also tried saving the tcp output in a global variable and tried reading it in the other form but that gives the same no print text output.

    Any ideas as to what I am not seeing??
    TIA
    Rick
    Last edited by rellison; Jul 26th, 2021 at 11:03 PM.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    107,467

    Re: TCPListener maybe thread issue??

    You haven't provided enough information to know for sure but this is almost certainly a case of default instances strike again. You should follow the Blog link in my signature below and read my post on Default Form Instances to learn what they are, how they differ from the alternative and why this issue occurs. If you still need help fixing the problem, show us the code that displays the second form in the first place and the code that calls that method.

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2001
    Posts
    33

    Re: TCPListener maybe thread issue??

    I still could not make this work by making the changes as suggested in your blog post. But I changed the layout of the program and removed the second Form. Now everything is working correctly and the invoke is showing that it is required and the invoke command takes care of that . Thanks so much for answering and getting me thinking on how to correct this..

    TIA
    Rick

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    107,467

    Re: TCPListener maybe thread issue??

    This issue or something like it is bound to come up again so I'd suggest learning how to do things properly now to avoid more headaches later. I would suggest that you show us what you did and we can tell you how it should have been done.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width