委托、线程的用法

委托用法简单步骤:

1,定义一个委托

public delegate void MyInvoke(TreeNode str); 

2,定义需投入委托操作的方法

/// <summary>
        
/// 1,利用this.Invoke封装添加节点   
        
/// 2,还原部分显示信息
        
/// </summary>
        private void CreateTreeNode(TreeNode node)
        {
            
this.trColorGroup.Nodes.Add(node);
            
if (trColorGroup.Nodes[0].Nodes.Count > 0)
                trColorGroup.SelectedNode 
= trColorGroup.Nodes[0].Nodes[0];
            
this.Text = this.Text.Replace(Definition.SHOW_WAITING_MESSAGE, "");
            
this.Enabled = true;
        }

3,执行委托

MyInvoke mi = new MyInvoke(CreateTreeNode);
this.Invoke(mi,firstLevelNode);


线程用法:

1,定义一个线程

Thread thread = null;

2,定义需用线程加载的方法

private void LoadColorGList(Object sWhere)
{
    
//带参数的方法
}

3,执行线程

thread = new Thread(new ParameterizedThreadStart(LoadColorGList));
thread.Start(sWhere);

 
4,终止线程

if (thread != null)
{
thread.Abort();
}
原文地址:https://www.cnblogs.com/xvqm00/p/1651551.html