Treeview Thread
-
Hi, I am wanting to create a Treeview Thread for loading the tree. I tried just calling the procedure that loads it and I got a control invoke issue. I have never created a thread before so I am looking for a sample if possible. Thanks Stephen
-
Hi, I am wanting to create a Treeview Thread for loading the tree. I tried just calling the procedure that loads it and I got a control invoke issue. I have never created a thread before so I am looking for a sample if possible. Thanks Stephen
StephenMcAllister wrote: I tried just calling the procedure that loads it and I got a control invoke issue. Controls should be manipulated in the application thread. At best, you can load your data into an in-memory table or some sort of structure using a thread, then populate the tree in the application thread. Marc MyXaml Advanced Unit Testing YAPO
-
Hi, I am wanting to create a Treeview Thread for loading the tree. I tried just calling the procedure that loads it and I got a control invoke issue. I have never created a thread before so I am looking for a sample if possible. Thanks Stephen
There's somenthing you can do. I've not done it, but I'm thinking it might be possible. You can see this article[^] but the main steps are something like this:
// 1. declare a delegate public delegate void AddTreeNodeHandler(TreeNode node); ... // 2. handler for the delegate void myAddTreeNode(TreeNode node) { treeView.Nodes.Add(node); } ... // 3. Start the thread (something like this.) // Pass any control created by main thread and delegate that will add node. MyThread t = new MyThread(treeView, new AddTreeNodeHandler(myAddTreeNode)); Thread t = new Thread(new ThreadStart(t.ThreadMain)); t.Start(); ... // 4. Thread class class MyThread { Control ctl; AddTreeNodeHandler atn; void MyThread(Control ctl, AddTreeNodeHandler atn) { this.ctl = ctl; // Save for later user this.atn = atn; } void ThreadMain() { while(all nodes you need to add) { TreeNode node = new TreeNode("text"); // This will post a call the delegate on the main thread, // and not block until it returns. The second parameter is an // array that will be passed as the arguments for the delegate. ctl.BeginInvoke(atn, new object[] { node }); } } }
I did it all from the top of my head, without checking docs, and obviously without compiling it, so it might have some mistakes. But it's a good start for what your trying to do. -- LuisR
Luis Alonso Ramos Intelectix - Chihuahua, Mexico Not much here: My CP Blog!
-
Hi, I am wanting to create a Treeview Thread for loading the tree. I tried just calling the procedure that loads it and I got a control invoke issue. I have never created a thread before so I am looking for a sample if possible. Thanks Stephen
This[^] article might help you. Regards Senthil _____________________________ My Blog | My Articles | WinMacro