I am doing
static bool isWorking { get { return _isWorking; } set { myform.treeView1.Enabled = !value; _isWorking = value; } }
and stepping through the debugger shows it stops at the first set line. After trying this line instead
set { myform.treeView1.Enabled = !(_isWorking = value); }
I see that isWorking is set but myform.treeView1.Enabled is not. Whats going on?
What do you mean by ‘the debugger shows it stops’? Is it possibly that
myformis null, ormyform.treeView1is null?I can’t remember the exact evaluation order in this case, but it could explain the symptoms you’re describing. Knowing why the debugger ‘stops’ is crucial though. Another possibility is that you’re trying to access the UI from a non-UI thread, which would prevent the assignment to
Enabledfrom working properly.Oh, and please don’t use your second version – assignment as a side-effect is very, very rarely a good idea. The only idiomatic use I know is when looping with IO:
and I only consider that acceptable because it’s reasonably common. In this case it really looks like you could mean ‘==’ instead of ‘=’.