我是C#的新手。在從另一個類中運行的線程更新WPF中的文本框時遇到問題。異常「類型'System.Object []'的對象不能轉換爲類型」
我的例外是:
類型的對象 'System.Object的[]' 不能轉換爲類型
這裏是我的表單代碼:
public void UpdateUserOnline(userOnlineClass message)
{
if(onLineTextbox.Dispatcher.CheckAccess())
{
// The calling thread owns the dispatcher, and hence the UI element
for (int i = 0; i < message.user.Length; i++)
{
// this.Dispatcher.Invoke(Action)
onLineTextbox.AppendText("•" + message.user + "\r\n");
onLineTextbox.AppendText(" ->" + message.status + "\r\n");
// txtDestination.Items.Add(message.user[i]);
}
}
else
{
// Invokation required
onLineTextbox.Dispatcher.Invoke(DispatcherPriority.Normal,new UpdateUserOnlineCallback(UpdateUserOnline), new Object[] { message });
}
}
而且這是我的Thread類中代碼的一部分:
thrMessaging = new Thread(new ThreadStart(ReceiveMessages));
thrMessaging.Start();
private void ReceiveMessages()
{
Response = null;
while (chatClient.Connected)
{
if (strm.DataAvailable)
{
Response = (commandClass)reciveFormatter.Deserialize(strm);
processMessage(Response);
//procProcessMessageCallback(processMessage), new object[] { Response });
//ProcessMessageCallback proccess = new ProcessMessageCallback(processMessage(Response));
}
}
}
private void processMessage(commandClass message)
{
/*
if (message.money != null)
{
UpdateUserRanking((userRankingClass)message.money);
}
*/
if (message.online != null)
{
waitinglist.UpdateUserOnline((userOnlineClass)message.online);
}
}
什麼是行拋出異常? – abatishchev 2012-01-12 15:02:42
嘗試調試並找出哪一行導致問題...我認爲你的錯誤信息是不完整的... – 2012-01-12 15:05:35
@abatishchev這裏 onLineTextbox.Dispatcher.Invoke(DispatcherPriority.Normal,new UpdateUserOnlineCallback(UpdateUserOnline),new Object [] {信息 } ); – 2012-01-12 15:11:26