相关疑难解决方法(0)

如何对ToolStripStatusLabel进行跨线程调用?

我倾向于在我的大多数应用程序的底部使用StatusStrip进行简单的状态更新,偶尔也会使用进度条.

但是,看起来ToolStripStatusLabels不会从控件继承,因此它们没有.Invoke或.InvokeRequired.那么我如何线程安全地调用来改变它的文本属性呢?

后代和其他搜索的代码答案:

Action<string> test=(text) =>
            {
                if (this._statusStrip.InvokeRequired) this._statusStrip.Invoke(
               new MethodInvoker(() => this._lblStatus.Text = text));
                else this._lblStatus.Text = text;
            };
Run Code Online (Sandbox Code Playgroud)

要么

private void TestInvoker(string text)
    {
        if (this._statusStrip.InvokeRequired) 
            this._statusStrip.Invoke(
                   new MethodInvoker(() => this._lblStatus.Text = text));
        else this._lblStatus.Text = text;
    }
Run Code Online (Sandbox Code Playgroud)

.net multithreading toolstrip

16
推荐指数
1
解决办法
1万
查看次数

标签 统计

.net ×1

multithreading ×1

toolstrip ×1