Hello,
This is my code:
vb.net Code:
Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Me.FolderBrowserDialog1.ShowDialog() If Me.FolderBrowserDialog1.SelectedPath <> String.Empty Then Me.TextBox2.Text = Me.FolderBrowserDialog1.SelectedPath Dim deleg As New Thread(AddressOf UpdateFileList) deleg.Start() End If Me.FolderBrowserDialog1.Reset() End Sub #End Region Private Sub UpdateFileList() Try Dim _filenames As ReadOnlyCollection(Of String) = My.Computer.FileSystem. _ GetFiles(Me.TextBox2.Text, FileIO.SearchOption.SearchAllSubDirectories) For Each filename As String In _filenames Me.ImageList1.Images.AddStrip(ExtractAssociatedIcon(filename).ToBitmap) If ListView1.InvokeRequired Then Me.ListView1.Invoke(New UpdateProgressCallBack(AddressOf UpdateFileList)) Else ListView1.Items. _ Add(filename, imageIndex:=Me.ImageList1.Images.Count - 1) _ .SubItems.Add(filename) End If Next Catch ex as Exception End Try End Sub
If I wanted to add 3 icons, the LV would add them like it normally would, but then, for some reason, it enters the loop again and that's when it throws this error:
ex = {"Cross-thread operation not valid: Control 'ListView1' accessed from a thread other than the thread it was created on."}
I don't understand why, because I'm invoking the LV...
Thanks in advance!





Reply With Quote