Disabling button not working
-
I need to disable my button because when the user presses it twice, I get an InvalidOperationException (backgroundWorker is busy and cannot run multiple tasks concurrently) in my form's code that is calling the form where I disable the button. In my btn_Program_Click method, I have
btn_Program.Enabled = false
, so it should be disabled, but the user can still click on it for some reason. Perhaps I'm misunderstanding what Enabled = false should be doing?? Thanks, Mich
-
I need to disable my button because when the user presses it twice, I get an InvalidOperationException (backgroundWorker is busy and cannot run multiple tasks concurrently) in my form's code that is calling the form where I disable the button. In my btn_Program_Click method, I have
btn_Program.Enabled = false
, so it should be disabled, but the user can still click on it for some reason. Perhaps I'm misunderstanding what Enabled = false should be doing?? Thanks, Mich
An easier fix would be just to unhook the click eventhandler before you create your event and just enable your click again in the threading complete handler.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier
-
I need to disable my button because when the user presses it twice, I get an InvalidOperationException (backgroundWorker is busy and cannot run multiple tasks concurrently) in my form's code that is calling the form where I disable the button. In my btn_Program_Click method, I have
btn_Program.Enabled = false
, so it should be disabled, but the user can still click on it for some reason. Perhaps I'm misunderstanding what Enabled = false should be doing?? Thanks, Mich
That should work. Are you sure you're not enabling it again -or- inadvertently trying to start another instrance of your background task? /ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
-
An easier fix would be just to unhook the click eventhandler before you create your event and just enable your click again in the threading complete handler.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier
-
Suppose you add the event handler like this:
myButton.Click += MyButton_Click;
Well, to remove the reference, all you need do is
myButton.Click -= MyButton_Click;
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier