| C# Winform跨线程更新UI控件值
					当前位置:点晴教程→知识管理交流
					
					→『 技术文档交流 』
					
				 
 在 Winforms 中, 所有的控件都包含  直接使用delegate void SetTextCallback(string text);
public void SetText(string text)
{
    if (InvokeRequired)
    {
        var d = new SetTextCallback(SetText);
        this.textBox1.Invoke(d, new object[] { text });
    }
    else
    {
        this.textBox1.Text = text;
    }
} 直接调用  使用扩展方法public static class MyClass
{
    public static void InvokeIfRequired(this ISynchronizeInvoke obj, MethodInvoker action)
    {
        if (obj.InvokeRequired)
        {
            var args = new object[0];
            obj.Invoke(action, args);
        }
        else
        {
            action();
        }
    }
} 使用: this.textBox1.InvokeIfRequired(() => { // Do anything you want with the control here this.textBox1.Text = "text"; }); 该文章在 2021/1/30 9:08:18 编辑过 | 关键字查询 相关文章 正在查询... |