4
Answers

cross threading seting form controls

I found something very curious today:

I have a standard c# Windows Form type program that has a couple of threads in it.

One thread is the "Stop" thread. In it, when the work of the thread is complete I want to re-enable some form controls.
 
Originally, Stop was run in the main thread but for other reasons, I had to put into a separate thread. So the code was unchanged from the beginning. Then I realized that there was another control I had to enable.
I added 'tsbPlay.Enabled=true' and as expected I got a cross threading error when I got there.
Then I noticed that just above I noticed that I was calling 'this.buttonx.enabled' all along with no problems. So I  change 'tsbPlay.Enabled=true' to 'this.tsbPlay.Enabled=true' and all worked error free.
Having successfully blown my mind I decided to ask the experts .
 
I'm sure that this method is probably not cool but why does it not work?
 
Thanks
Moose
 
P.S. I'm using VS2005. 
Answers (4)