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

 


 

你可能感兴趣的:(多线程更新form)