Threading issue: can't see controls even though visible = true

  • Thread starter Thread starter Confused White Guy
  • Start date Start date
C

Confused White Guy

I have a C# winforms app in which I am calling a method on a different
thread, using the Thread.Start() method. The method that is being
executed on the new thread attempts to make a button visible and a
panel visible after doing some work asynchronously. The button and
panel are private to the form that contains both the method that
starts the new thread (i.e. the calling method) and the method that
the new thread executes. While debugging, and just before exiting from
the new thread method call, I can see that the button visible property
is true and the panel visible property is true, however when the form
finally renders, neither of the controls can be seen. Moreover, I have
verified that the visible property of the panel is true and executed
the BringToFront method of the panel after the form renders. The form
window handle of the calling method is the same as that of the method
executed on the new thread.

I am pretty sure that the new thread is operating on the same form
object/instance as the calling thread since I can successfully modify
the background color (I see the color change on the screen) of the
calling form and I can close the calling form from within the method
that is executed on the new thread.

Interestingly, if the button and panel do not initially have visible =
false, I have no problems setting the visibility to false and back to
true.

I can supply code if desired.

I am absolutely baffled by this.

TIA

Shaun
 
I'm surprised this isn't blowing up all over the place, you must be running
on an NT box.
You've violated a major threading rule here. Thou shall have no other Gods
but me...oops sorry (that was meant for the preacher in here)
Thou shall not modify UI objects with a child thread, only the main thread.
 
You've violated a major threading rule here. Thou shall have no other Gods
but me...oops sorry (that was meant for the preacher in here)

<snip>

I'm not sure what it says about me that my first reaction to that
wasn't to think of my preaching, but to think of the pilot episode of
the West Wing...
 
Back
Top