"Robin Tucker" <id*************************@reallyidont.com> schrieb
Ouch. I've got a nasty problem here.
I need to load a tree structure into a treeview from a database.
I've just tested it with 10,000 items and its dog slow (one of the
main reasons is because I am manually "filtering" the items with my
own filtering structures). What I want to do is run a thread which
constructs the TreeView (and nodes) so that the rest of the GUI
remains responsive. Then, when the thread completes, I want to then
marshal this TreeView structure into the main process so that I can
use it (at least make mainprocess.TreeView.Nodes =
threadprocess.TreeView.Nodes).
(why to the Interop group?)
Class CreateNodesThread
Private m_Thread As Threading.Thread
Public Event Done(ByVal Nodes As TreeNode())
Sub Start()
m_Thread = New Threading.Thread(AddressOf ThreadProc)
m_Thread.Start()
End Sub
Private Sub ThreadProc()
Dim Nodes(1) As TreeNode
Nodes(0) = New TreeNode("1")
Nodes(1) = New TreeNode("2")
RaiseEvent Done(Nodes)
End Sub
End Class
In a Form:
Private m_CreateNodesThread As CreateNodesThread
Private Sub OnCreateNodesThreadDone(ByVal Nodes As TreeNode())
If TreeView1.InvokeRequired Then
TreeView1.BeginInvoke( _
New CreateNodesThread.DoneEventHandler( _
AddressOf OnCreateNodesThreadDone _
), _
New Object() {Nodes} _
)
Else
RemoveHandler m_CreateNodesThread.Done, _
AddressOf OnCreateNodesThreadDone
m_CreateNodesThread = Nothing
TreeView1.Nodes.AddRange(Nodes)
End If
End Sub
Start the job:
m_CreateNodesThread = New CreateNodesThread
AddHandler m_CreateNodesThread.Done, AddressOf OnCreateNodesThreadDone
m_CreateNodesThread.Start()
--
Armin
How to quote and why:
http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html