hi all,
I'm having a few problems whereby my application is hanging when using the
Invoke method of a form's control.
Basically, when a user clicks a button on the form, it calls a remote
function, which in turn fires an event that is caught by the form.
The form then need to add a value passed in the event to a form object,
however, when using the Invoke method, it just hangs.
Here's a snippet of the code;
public void NotifyUserAdded(string username)
{
TreeNodeCollection treeNodeCollection = treeMachines.Nodes[0].Nodes;
TreeNode treeNodeParent = treeMachines.Nodes[0];
AddDelegate addDelegate = new AddDelegate(treeNodeCollection.Add);
ExpandDelegate expandNodeDelegate = new
ExpandDelegate(treeNodeParent.Expand);
treeMachines.Invoke(addDelegate, new object[] {new
TreeNode(username,0,0)});
treeMachines.Invoke(expandNodeDelegate);
}
the two delegates are obviously previously defined.
delegate int AddDelegate(TreeNode treeNode);
delegate void ExpandDelegate();
Sometimes it works, but it's very slow. If i take the invoke out and use
the Node.Add method, it works... but obviously not correctly - as 50% of the
time it throws the "must use invoke" exception.
Any ideas?
TIA
Sam Martin