繁体   English   中英

线程:设置复选框的可见性

[英]Threading: Setting checkbox's visibility

在C#.NET Windows应用程序(winforms)中,我将复选框的可见性设置为false:

checkBoxLaunch.Visible = true;

我开始了一个话题。

Thread th = new Thread(new ThreadStart(PerformAction));
th.IsBackground = true;
th.Start();

该线程执行一些操作并将可见性设置为true:

private void PerformAction()
{
/*
.
.// some actions.
*/
    checkBoxLaunch.Visible = true;

}

线程完成其任务后,该复选框对我不可见。

我想念什么?

您不应该在非UI线程内进行UI更改。 使用Control.InvokeControl.BeginInvokeBackgroundWorker将呼叫Control.BeginInvoke送回UI线程。 例如(假设C#3):

private void PerformAction()
{
/*
.
.// some actions.
*/
    MethodInvoker action = () => checkBoxLaunch.Visible = true;
    checkBoxLaunch.BeginInvoke(action);
}

搜索Control.Invoke,Control.BeginInvoke或BackgroundWorker中的任何内容,以查找有关此内容的数百篇文章。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM