多线程更新form

public void UIThread(MethodInvoker method)
{
    if (this.InvokeRequired)
    {
        this.Invoke(method);
    }
    else
    {
        method.Invoke();
    }
}

public void UpdateUI()
{
    this.UIThread(delegate
    {
        this.Label1.Text = "msg1";
        this.Label2.Text = "msg2";
    });
}
public void UpdateUI()
{
    if (this.InvokeRequired)
    {
        this.Invoke(new MethodInvoker(delegate { UpdateUI(); }));
    }
    else
    {
        this.Label.Text = "msg1";
        this.Labe2.Text = "msg2";
    }
}
public void UIThread(MethodInvoker method)
{
    if (this.InvokeRequired)
    {
        this.Invoke(method);
    }
    else
    {
        method.Invoke();
    }
}

public void UpdateUI()
{
    this.UIThread(delegate
    {
        this.Label1.Text = "msg1";
        this.Label2.Text = "msg2";
    });
}


 

    
作者:wanglei_wan
    
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
原文地址:https://www.cnblogs.com/because/p/2698538.html