多线程更新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";
    });
}

 


 

posted @ 2012-09-22 22:52  璇星  阅读(361)  评论(0编辑  收藏  举报