我如何“调用”绕过交叉线程问题? [英] How do I "invoke" to get around cross threading problems?

查看:54
本文介绍了我如何“调用”绕过交叉线程问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从其他线程设置工具条按钮的状态。我已经确定需要调用...但我只是不明白C#才能弄明白该做什么。



我有:

I'm trying to set the status of a toolstrip button from a different thread. I've determined that an invoke is required...but I just don't understand enough C# to figure out what to do.

I have:

if (toolStrip1.InvokeRequired)
{
	// What do I put here?
}
else
{
	tsImportButton.Enabled = true;
	tsImportButton.Checked = false;
}





我的尝试:



我试过理解C#并且失败了...



What I have tried:

I've tried understanding C# and failed...

推荐答案

阅读: ToolStrip.Invoke,System.Windows.Forms C#(CSharp)代码示例 - HotExamples [< a href =https://csharp.hotexamples.com/examples/System.Windows.Forms/ToolStrip/Invoke/php-toolstrip-invoke-method-examples.html\"target =_ blanktitle =New Window> ^ ]


除了解决方案1,我还想推荐以下内容:

如何:对Windows窗体控件进行线程安全调用Microsoft Docs [ ^ ]
In addition to solution 1 I would like to recommend the following:
How to: Make Thread-Safe Calls to Windows Forms Controls | Microsoft Docs[^]


这篇关于我如何“调用”绕过交叉线程问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆