HighTechTalks DotNet Forums  

Marshal a tree structure across threads?

VB.net microsoft.public.dotnet.languages.vb


Discuss Marshal a tree structure across threads? in the VB.net forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Robin Tucker
 
Posts: n/a

Default Marshal a tree structure across threads? - 05-05-2004 , 09:50 AM






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).

Any ideas?





Reply With Quote
  #2  
Old   
Armin Zingler
 
Posts: n/a

Default Re: Marshal a tree structure across threads? - 05-05-2004 , 10:26 AM






"Robin Tucker" <idontwanttobespammedanymore (AT) reallyidont (DOT) com> schrieb
Quote:
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



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.