views:

21

answers:

1

In a C#.NET windows application I set the visibility of the checkbox to false:

checkBoxLaunch.Visible = true;

I started a thread.

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

The thread performs some stuff and sets the visibility to true

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

}

But after the thread finishes it's task, the check box is not visible to me.. :(

What am I missing??

+3  A: 

You shouldn't make UI changes within a non-UI thread. Use Control.Invoke, Control.BeginInvoke or BackgroundWorker to marshal the call back to the UI thread. For example (assuming C# 3):

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

Search for any of Control.Invoke, Control.BeginInvoke or BackgroundWorker to find hundreds of articles about this.

Jon Skeet
Great...thanks !!
Manish