【发布时间】:2014-04-22 06:39:59
【问题描述】:
我正在尝试更新树视图,但收到一个错误,提示我无法将 Obj 转换为字符串。
我正在创建一个使用多个线程的扫描仪,一旦检查了每个项目,我想调用一个委托来使用新信息更新树视图。如果我只使用对象调用该方法,则可以轻松调用它来更新信息,但一旦我尝试使用字符串,我就会收到错误。
这是我的做法:
public delegate void StringDelegate(string input, string address);
public void UpdateScan(string input, string ip)
{
TreeNode treeNode = new TreeNode(input);
if (!(outputTree.Nodes.ContainsKey(input)))
{
//Add our parent node
outputTree.Nodes.Add(treeNode);
//Add our child node
treeNode.Nodes.Add(ip);
}
else
{
//Add only child node
treeNode.Nodes.Add(ip);
}
}
public void scanItem()
{
//Scan code
//Result Code
string outPut = "Pretend Result";
//Invoke our callback
object[] obj = new object[1];
obj[0] = outPut;
outputTree.BeginInvoke(new StringDelegate(UpdateScan), obj, Ip.ToString());
}
谁能告诉我哪里出错了?
【问题讨论】:
标签: c# .net multithreading treeview