Threading and Listview optimization questions

A

André Nogueira

Hi there.
I am developing an explorer-like application.
However, there is one problem.
If the current dir has many files, it will take a while to populate the
listview with all the files and folders.
How can I overcome this? Programs such as Total Commander have no problem
what so ever. So is there anything I can do?
Also, how can I populate both the treeview and the listview from a new
thread?
I have already tried

Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
TN = e.Node
Dim T As New Threading.Thread(AddressOf ThUpd)
T.Start()
End Sub

Sub ThUpd()
Dim mi As New MethodInvoker(AddressOf Me.UpdateViews)
Me.BeginInvoke(mi)
End Sub

But that makes the program run as if no new thread was created and still
blocks the user from using the program's UI.

Thank you!
 
M

Mattias Sjögren

André,
Sub ThUpd()
Dim mi As New MethodInvoker(AddressOf Me.UpdateViews)
Me.BeginInvoke(mi)
End Sub

But that makes the program run as if no new thread was created and still
blocks the user from using the program's UI.

I assume most of your work is done in the UpdateViews method, which
still executes on the UI thread. You have to move the time consuming
task to execute on the background thread, and then only use the UI
thread for inserting the new item in the control.



Mattias
 
A

André Nogueira

And how do I do that? My problem is adding items to the listview and the
treeview from a thread...
I need to add nodes to the "e" object passed on to the TreeView1_AfterSelect
sub.

André Nogueira
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top