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. Invoking Progressbar

Invoking Progressbar

Scheduled Pinned Locked Moved C#
question
9 Posts 4 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.
  • S Offline
    S Offline
    SimpleData
    wrote on last edited by
    #1

    Hi, I need to control my progressbar inside a thread by invoking it on GUI thread, otherwise the GUI may lock for a short time which is really disturbing. How can I change the Value property of a progressbar with invoking it. Thanks in advance.

    L A 2 Replies Last reply
    0
    • S SimpleData

      Hi, I need to control my progressbar inside a thread by invoking it on GUI thread, otherwise the GUI may lock for a short time which is really disturbing. How can I change the Value property of a progressbar with invoking it. Thanks in advance.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      the thread-and-control stuff is the same for all kinds of Controls. This[^] may help a bit. :)

      Luc Pattyn


      I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


      Local announcement (Antwerp region): Lange Wapper? Neen!


      S 1 Reply Last reply
      0
      • S SimpleData

        Hi, I need to control my progressbar inside a thread by invoking it on GUI thread, otherwise the GUI may lock for a short time which is really disturbing. How can I change the Value property of a progressbar with invoking it. Thanks in advance.

        A Offline
        A Offline
        Abhijit Jana
        wrote on last edited by
        #3

        I think you are looking for Background Worker :) Have a look into this, It may help you ! Using the BackgroundWorker Component in .NET 2 applications[^]

        Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Visit My Latest Article : Beginner's Guide : Exploring IIS 6.0 With ASP.NET

        1 Reply Last reply
        0
        • L Luc Pattyn

          the thread-and-control stuff is the same for all kinds of Controls. This[^] may help a bit. :)

          Luc Pattyn


          I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


          Local announcement (Antwerp region): Lange Wapper? Neen!


          S Offline
          S Offline
          SimpleData
          wrote on last edited by
          #4

          Thank you, that article is perfect.

          L 1 Reply Last reply
          0
          • S SimpleData

            Thank you, that article is perfect.

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            I'll make sure and tell the author. :-D

            Luc Pattyn


            I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


            Local announcement (Antwerp region): Lange Wapper? Neen!


            S 1 Reply Last reply
            0
            • L Luc Pattyn

              I'll make sure and tell the author. :-D

              Luc Pattyn


              I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


              Local announcement (Antwerp region): Lange Wapper? Neen!


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

              I implemented the solution to my project easily, but there is only one problem. I need to change the enabled property of a ToolStripMenuItem inside a thread and ToolStripMenuItem is not a Control. Therefore, I can't use this method. What can I do?

              D 1 Reply Last reply
              0
              • S SimpleData

                I implemented the solution to my project easily, but there is only one problem. I need to change the enabled property of a ToolStripMenuItem inside a thread and ToolStripMenuItem is not a Control. Therefore, I can't use this method. What can I do?

                D Offline
                D Offline
                DaveyM69
                wrote on last edited by
                #7

                Use the control that owns the item, so either the ToolStrip or the form. Set up a delegate there that invokes a method that sets the enabled state, and invoke that delegate as you would any other.

                Dave
                Generic BackgroundWorker - My latest article!
                BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
                Why are you using VB6? Do you hate yourself? (Christian Graus)

                S 1 Reply Last reply
                0
                • D DaveyM69

                  Use the control that owns the item, so either the ToolStrip or the form. Set up a delegate there that invokes a method that sets the enabled state, and invoke that delegate as you would any other.

                  Dave
                  Generic BackgroundWorker - My latest article!
                  BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
                  Why are you using VB6? Do you hate yourself? (Christian Graus)

                  S Offline
                  S Offline
                  SimpleData
                  wrote on last edited by
                  #8

                  I came up with this, is this a good solution?

                  public delegate void ControlTSBoolConsumer(ContextMenuStrip cms, ToolStripMenuItem tsmi, bool choice);
                  private void SetTSEnabled(ContextMenuStrip cms, ToolStripMenuItem tsmi, bool choice)
                  {
                  if (cms.InvokeRequired)
                  cms.Invoke(new ControlTSBoolConsumer(SetTSEnabled), new object[] { cms, tsmi, choice });
                  else
                  tsmi.Enabled = choice;
                  }

                  L 1 Reply Last reply
                  0
                  • S SimpleData

                    I came up with this, is this a good solution?

                    public delegate void ControlTSBoolConsumer(ContextMenuStrip cms, ToolStripMenuItem tsmi, bool choice);
                    private void SetTSEnabled(ContextMenuStrip cms, ToolStripMenuItem tsmi, bool choice)
                    {
                    if (cms.InvokeRequired)
                    cms.Invoke(new ControlTSBoolConsumer(SetTSEnabled), new object[] { cms, tsmi, choice });
                    else
                    tsmi.Enabled = choice;
                    }

                    L Offline
                    L Offline
                    Luc Pattyn
                    wrote on last edited by
                    #9

                    I expect that to work fine. I am aware the MSDN documentation doesn't say much about this, and neither does my article. I probably should add the following paragraph: There are several items that Visual Designer can add to a Form although they aren't Controls; they are either parts of a Control (e.g. MenuItem, ToolStripMenuItem, ...) or Components (Forms.Timer, SerialPort, ...); for all of these I think a good approach is to choose a Control on which InvokeRequired/Invoke can be used; the Form itself is a good candidate for solving threading unsafety issues. :)

                    Luc Pattyn


                    I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


                    Local announcement (Antwerp region): Lange Wapper? Neen!


                    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