Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Disabling button not working

Disabling button not working

Scheduled Pinned Locked Moved C#
question
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MichCl
    wrote on last edited by
    #1

    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

    P R 2 Replies Last reply
    0
    • M MichCl

      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

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      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

      M 1 Reply Last reply
      0
      • M MichCl

        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

        R Offline
        R Offline
        Ravi Bhavnani
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • P Pete OHanlon

          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

          M Offline
          M Offline
          MichCl
          wrote on last edited by
          #4

          How is the click eventhandler disabled?

          P 1 Reply Last reply
          0
          • M MichCl

            How is the click eventhandler disabled?

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups