Hi there,
I use threads to process something and then to display the result in a treeview.
This code works but the problem it does not add until all threads finishes. I want to keep adding as long as I am in FindFolders()
Here is my code:
VB Code:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Net; using System.Net.Sockets; using System.Threading; using System.Collections; namespace MyProject { public partial class Form1 : Form { private delegate void AddNodeToTreeViewDelegate(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { int j; for (j = 1; j < 10; j++) { ThreadStart starter = new ThreadStart(FindFolders); Thread t = new Thread(starter); t.Start(); } } private void FindFolders() { //assume this is the folder name I want to display in the treeview string folder_name = "test"; [COLOR=Red]treeView1.Invoke(new AddNodeToTreeViewDelegate(AddNodeToTreeView), new object[] { folder_name });[/COLOR] } private void AddNodeToTreeView(string fname) { TreeNode p = new TreeNode(fname); treeView1.Nodes.Add(p); } } }


Reply With Quote