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. Cross-thread ToolStripButton update

Cross-thread ToolStripButton update

Scheduled Pinned Locked Moved C#
questionannouncement
6 Posts 5 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.
  • A Offline
    A Offline
    aei_totten
    wrote on last edited by
    #1

    I generally use this method to update buttons cross-thread, but ToolStripButtons don't have the InvokeRequired property. delegate void UpdateStartDelegate(bool newState); private void updateStartButton(bool newState) { if (startButton.InvokeRequired) // is cross-thread update Invoke(new UpdateStartDelegate(updateStartButton), new object[] { newState }); else startButton.Enabled = newState; } Is there an easy way to do the same thing with a ToolStripButton?

    N H S 3 Replies Last reply
    0
    • A aei_totten

      I generally use this method to update buttons cross-thread, but ToolStripButtons don't have the InvokeRequired property. delegate void UpdateStartDelegate(bool newState); private void updateStartButton(bool newState) { if (startButton.InvokeRequired) // is cross-thread update Invoke(new UpdateStartDelegate(updateStartButton), new object[] { newState }); else startButton.Enabled = newState; } Is there an easy way to do the same thing with a ToolStripButton?

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      ((Control)btn).InvokeRequired


      only two letters away from being an asset

      M 1 Reply Last reply
      0
      • A aei_totten

        I generally use this method to update buttons cross-thread, but ToolStripButtons don't have the InvokeRequired property. delegate void UpdateStartDelegate(bool newState); private void updateStartButton(bool newState) { if (startButton.InvokeRequired) // is cross-thread update Invoke(new UpdateStartDelegate(updateStartButton), new object[] { newState }); else startButton.Enabled = newState; } Is there an easy way to do the same thing with a ToolStripButton?

        H Offline
        H Offline
        Hesham Yassin
        wrote on last edited by
        #3

        use a synchronous calls using a timer

        1 Reply Last reply
        0
        • N Not Active

          ((Control)btn).InvokeRequired


          only two letters away from being an asset

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

          All ToolStripItems (suach as ToolStripButton) are only of type Component. They don't inherit from Control. Regards.

          N 1 Reply Last reply
          0
          • M mabo42

            All ToolStripItems (suach as ToolStripButton) are only of type Component. They don't inherit from Control. Regards.

            N Offline
            N Offline
            Not Active
            wrote on last edited by
            #5

            You're correct, my mistake


            only two letters away from being an asset

            1 Reply Last reply
            0
            • A aei_totten

              I generally use this method to update buttons cross-thread, but ToolStripButtons don't have the InvokeRequired property. delegate void UpdateStartDelegate(bool newState); private void updateStartButton(bool newState) { if (startButton.InvokeRequired) // is cross-thread update Invoke(new UpdateStartDelegate(updateStartButton), new object[] { newState }); else startButton.Enabled = newState; } Is there an easy way to do the same thing with a ToolStripButton?

              S Offline
              S Offline
              spainchaud
              wrote on last edited by
              #6

              I apologize for posting on an old thread, but I had the exact same question, and there did not seem to be an answer to this one. Someone mentioned using a timer, but my cross-thread could take several seconds, several minutes, or several hours. I think I came up with an answer, so for future searchers I decided to post. I would test the ToolStrip that contained the button. This code seems to work to enable a toolstripbutton when a thread is done. public void Enable() { if (toolStrip.InvokeRequired) { EnableButtonCallback d = new EnableButtonCallback(Enable); toolStrip.Invoke(d, new object[] { }); } else { button.Enabled = true; } }

              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