当前位置:编程学习 > C#/ASP.NET >>

请教C#多线程更新TreeView节点问题

在MSDN上看到在多线程中安全更新控件内容,其他控件用托管方式是没问题但是在TreeView中要出问题,代码如下
private void SetTreeViewNode(string text)
        {
            if (this.treeView1.InvokeRequired)
            {
                SetTreeCallback stc = new SetTreeCallback(SetTreeViewNode); ;
                this.Invoke(stc,new object[]{text});
            }
            else
            {
                string[] strTemp = Thread.CurrentThread.Name.Split('|');
                TreeNode tn = new TreeNode();
                tn.Name = DesIpAddress;
                tn.Text = text;
                treeView1.Nodes[strTemp[0]].Nodes.Add(tn);
            }
            
        }

请教应如何修改,请给出代码,谢谢 --------------------编程问答-------------------- 什么问题?一般是没有问题的;this.Invoke(stc,new object[]{text});
this改为TreeView1 --------------------编程问答-------------------- public void listViewAddNode(string URL, int N)
        {
            if (this.treeView1.InvokeRequired)
            {

                Invoke(new listViewAddNodeEventHandler(delegate(string url, int n)
               {
                       this.treeView1.Nodes[n].Nodes.Add(url);

               }), new object[] { URL, N });
            }
            else
            {
                    this.treeView1.Nodes[N].Nodes.Add(URL);

           }
        }
http://www.csharpwin.com/csharpspace/10538r6779.shtml
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,