title: Adding text to a list view from threads
body: <p>I am new to VB and I am trying to add text from a thread to a <code>listview</code> in my Form1.</p>
  
  <p>I have tried implementing the <code>invokerequired</code> method but still the new text is not added to my <code>listview</code>. </p>
  
  <p>(please see function <code>addlvDataItem</code>)</p>
  
  <p>This what I call in my thread class:</p>
  
  <pre><code>Private Sub DoServerListening()
      'Thread to listen for new incoming socket clients
      Dim mSocket As System.Net.Sockets.Socket
      Dim newConnectionThread As clsTCPConnection
      Dim strRemoteIPAddress As String
  
      Do
          Try
              While bServerRunning = True
                  If mTCPListener.Pending = True Then
  
                      mSocket = mTCPListener.AcceptSocket()
                      'mSocket.Blocking = True
                      If mSocket.Connected Then
                          strRemoteIPAddress = Split(mSocket.RemoteEndPoint.ToString, ":")(0)
                          newConnectionThread = New clsTCPConnection(mSocket, strRemoteIPAddress)
                          'Start the thread to handle this connection
                          Form1.addlvDataItem("Connected to " &amp; strRemoteIPAddress.ToString(), 0)
                          Dim myThread As New System.Threading.Thread(AddressOf newConnectionThread.HandleConnection)
                          myThread.Start()
                      End If
                  End If
  
              End While
          Catch ex As Exception
              If bServerRunning = True Then
                  'notify main application
  
              End If
          End Try
  
      Loop
  
  End Sub
  </code></pre>
  
  <p>and this is what i do in my Form1 class</p>
  
  <pre><code>Public Delegate Sub addlvDataItemCallback(ByVal [text] As String, ByVal Num As Integer)
  
  Public Sub addlvDataItem(ByVal [text] As String, ByVal Type As Integer)
      CurrentDateTime = DateTime.Now
  
      If lvData.InvokeRequired Then
          Dim d As New addlvDataItemCallback(AddressOf addlvDataItem)
          Me.Invoke(d, New Object() {[text]})
      Else
          If Type = 1 Then 'TX
              Me.lvData.Items.Add("TX (" + text.Length.ToString() + " bytes): " + CurrentDateTime + " : &lt;Start&gt; " + text.ToString() + "&lt;End&gt;")
          ElseIf Type = 2 Then
              Me.lvData.Items.Add("RX (" + text.Length.ToString() + " bytes): " + CurrentDateTime + " : &lt;Start&gt; " + text.ToString() + "&lt;End&gt;")
          Else
              Me.lvData.Items.Add("Info: " + CurrentDateTime + " : " + text.ToString())
  
          End If
      End If
  End Sub
  </code></pre>
  
  <p>The new text that I add is not displayed in the listview. I do not get any compile or runtime errors but still no new text to list box. I can add text from my Form1 class but not from the thread.</p>