HastaLaVictoria
Newcomer
G'day X.NET!
I have a dilly of a pickle here, wondering if anyone can help a neighbourino out. </flanders>
I have an application I'm building that uses asynchronous TCP connections to ferry data about between a server and multiple clients. I'm trying to implement a TreeView on my server UI form that will display all the connected clients' usernames.
The problem I'm having is that I've written a method populateUserTree(), and called it from my receiveEvent() method, which is an AsyncCallback for BeginReceive. Whoops! Doesn't work, as the thread I'm in can't access the controls on the form. The error message hints at using Control.Invoke to achieve this, but the MSDN page on it isn't all that helpful.
I took a stab in the dark and had my receiveEvent method call treeClients.Invoke(populateUserTree);, but that didn't work. The compile error was that a 'method group' could not be converted to a 'Delegate', so I presumed I got it horribly wrong and went on an Interwebs search for the answer. I found an MSDN article on delegates but it wasn't explaning what I wanted.
Alas, nothing. So, in closing, can anyone provide an explanation, or example, of how to use Invoke to get a TreeView on a form to update, originating in another thread?
The code I'm using to perform the actual updates to the TreeView treeClient is:
Thanks to anyone who can help.
-Dru
I have a dilly of a pickle here, wondering if anyone can help a neighbourino out. </flanders>
I have an application I'm building that uses asynchronous TCP connections to ferry data about between a server and multiple clients. I'm trying to implement a TreeView on my server UI form that will display all the connected clients' usernames.
The problem I'm having is that I've written a method populateUserTree(), and called it from my receiveEvent() method, which is an AsyncCallback for BeginReceive. Whoops! Doesn't work, as the thread I'm in can't access the controls on the form. The error message hints at using Control.Invoke to achieve this, but the MSDN page on it isn't all that helpful.
I took a stab in the dark and had my receiveEvent method call treeClients.Invoke(populateUserTree);, but that didn't work. The compile error was that a 'method group' could not be converted to a 'Delegate', so I presumed I got it horribly wrong and went on an Interwebs search for the answer. I found an MSDN article on delegates but it wasn't explaning what I wanted.
Alas, nothing. So, in closing, can anyone provide an explanation, or example, of how to use Invoke to get a TreeView on a form to update, originating in another thread?
The code I'm using to perform the actual updates to the TreeView treeClient is:
Code:
treeClients.BeginUpdate();
treeClients.Nodes.Clear();
treeClients.Nodes.Add("Connected Clients");
foreach (ClientItem clientInfo in clientList)
{
treeClients.Nodes[0].Nodes.Add(clientInfo.strName);
}
treeClients.EndUpdate();
Thanks to anyone who can help.
-Dru