2014-12-13 76 views
0

以下是客户端处理程序类的一段代码。Gui正在调用参数

我知道我传递了错误信息,如下面注释中所述。我只需要确切地知道我应该通过什么才能使其工作。

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()); 

    } 
+0

什么是uiDispatcher的类型? – dotnetstep 2014-12-13 02:31:48

回答

1

,似乎是唯一缺少的就是你的参数去传递给委托,我假设你想要的以下内容:

uiDispatcher.CurrentDispatcher.BeginInvoke(addToClientListBox, new object[]{"ParamString"}, DispatcherPriority.Background); 

如果这不是正是你在问什么让我知道: )

0
Delegate d = (Action<string>)add2ClientList; 
uiDispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, d, c.getClientIp());