2014-12-13 75 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());