2010-03-24 26 views
1

在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; 

} 

後,該複選框對我來說並不可見。

我錯過了什麼?

+0

「...我將複選框的可見性設置爲false:」...但是您的錯誤讀取像真^^ – tanascius 2010-03-24 10:17:23

回答

5

您不應該在非UI線程內進行UI更改。使用Control.Invoke,Control.BeginInvokeBackgroundWorker將回調封送回UI線程。例如(假設C#3):

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

搜索任何Control.Invoke,Control.BeginInvoke或BackgroundWorker的,找到數百篇關於這個的文章。

+0

太好了......謝謝! – Manish 2010-03-24 10:59:13