I have a recursive function with some loops that I use to populate a TreeView with a list of files and folders. In some situations this can take a bit of time to execute especially when loading a lot of files.
I wish to show a progress bar to show how far through the loading process I am.
I have searched everywhere for this and tried with a BackgroundWorker and am now very lost.
Sorry I'm not really sure what code to share but please let me know if you need to see any of the functions/routines.
The error I get with the background worker is a System.InvalidOperationException "Action being performed on this control is being called from the wrong thread."
Background Worker_DoWork:
For i = 0 To 100
PopulateTreeView()
BackgrondWorked.ReportProgress(i)
Next
PopulateTreeView Sub:
Dim node As TreeNode = New TreeNode
node.Text = "Music"
TreeView.Nodes.Add(node)
GetFilesAndFolders("D:\Music", node)
This throws the error described above when trying to add the first node with text "Music"
Any suggestions will be greatly appreciated. Thanks.