Reputation: 1808
Below is a segment of code from a client handler class.
I know I am passing the wrong information as noted in the comment below. I just need to know exactly what I should pass to make it work.
public static void add2ClientList(string s)
{
MainWindow.mainWindow.ClientListBox.Items.Add(s);
}
Action<string> addToClientListBox = new Action<string> (add2ClientList);
public void addClientToPool(Client c)
{
if (ClientPool == null)
{
ClientPool = new Client[] { c };
uiDispatcher.BeginInvoke(addToClientListBox, DispatcherPriority.Background, CancellationToken.None, TimeSpan.Zero, c.getClientIp());
// above is the issue apparently I am passing the wrong params
return;
}
List<Client> temp = new List<Client>();
foreach (Client cc in ClientPool)
{
temp.Add(cc);
}
temp.Add(c);
ClientPool = temp.ToArray();
uiDispatcher.BeginInvoke(addToClientListBox, DispatcherPriority.Background, CancellationToken.None, TimeSpan.Zero, c.getClientIp());
}
Upvotes: 0
Views: 22
Reputation: 17485
Delegate d = (Action<string>)add2ClientList;
uiDispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, d, c.getClientIp());
Upvotes: 0
Reputation: 1185
The only thing that appears to be missing is your param to pass to the delegate, I assume you want the following:
uiDispatcher.CurrentDispatcher.BeginInvoke(addToClientListBox, new object[]{"ParamString"}, DispatcherPriority.Background);
If that's not exactly what you were asking let me know :)
Upvotes: 1