Hi,
..NET framework does not support InvokeRequired and does not allow you
to pass arguments to the delegate called by Invoke. A workaround might
be using a private to store the node to add. It might be OK as long as
updating UI is done less than often from the non-UI thread. That worker
thread should focus on its main task, and only update UI on some
occasions.
// these var is used to communicate between threads
private TreeNode parentNode;
private TreeNode nodeToAdd;
private object syncObj = new Object();
public void AddNodeFromUIThread(object sender, System.EventArgs e)
{
if (parentNode != null)
{
parentNode.Nodes.Add(nodeToAdd);
}
else
{
TreeView t = (TreeView) sender;
t.Nodes.Add(nodeToAdd);
}
}
public void AddNodeFromOtherThread(TreeNode parentNode, TreeNode
nodeToAdd)
{
lock (syncObj)
{
this.parentNode = parentNode;
this.nodeToAdd = nodeToAdd;
treeView1.Invoke(new EventHandler(AddNodeFromUIThread));
}
}
Thi