When using like this it gives error.
SetListBoxText(lstFileName, "", True)
Cross-thread operation not valid: Control 'lstFileName' accessed from a thread other than the thread it was created on.
Delegate Sub SetListBoxInvoker(ByVal listBox As ListBox, ByVal Text As String)
Sub SetListBoxText(ByVal listBox As ListBox, ByVal Text As String, Optional ByVal ClearAll As Boolean = False)
Try
If ClearAll = True Then
listBox.Items.Clear()
End If
If listBox.InvokeRequired = True Then
listBox.Invoke(New SetListBoxInvoker(AddressOf SetListBoxText), listBox, Text, False)
Else
listBox.Items.Add(Text)
End If
Catch ex As Exception
End Try
End Sub
Delegate Sub SetListBoxSelectedInvoker(ByVal listBox As ListBox, ByVal Text As String)
Sub SetListBoxSelected(ByVal listBox As ListBox, ByVal Text As String)
Try
If listBox.InvokeRequired = True Then
listBox.Invoke(New SetListBoxSelectedInvoker(AddressOf SetListBoxSelected), listBox, Text)
Else
listBox.SelectedItem = Text
End If
Catch ex As Exception
End Try
End Sub