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. Windows Forms
  4. issue with progress bar

issue with progress bar

Scheduled Pinned Locked Moved Windows Forms
helptutorial
3 Posts 2 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.
  • G Offline
    G Offline
    gtag
    wrote on last edited by
    #1

    There are two issues : 1. My windows application contain many number of controls like, buttons, textboxes,checkboxes etc.. Application is very slow while execution and even for any button click event application hangs for a while(atleast 8 seconds). Used panel and group box but same status. 2.While execution i have to show one progress bar for particular button click event. And need to increment progress bar in sync or simultaneously with button click event execution. Example: (only a part of the code i am writing here in blog): Two forms form1 & form2: on form1 button click event some code is executed. say form1 code: form2 trs = new form2(); btn_click { trs.Show(); trs.Owner = this; trs.go(this); Thread thred = new Thread(new ParameterizedThreadStart(trs.go)); string strngmain = "a"; ....do something........(here actual code executes, while this executes,i want to show the status in progress bar, so while execution i am adding one char to string variable strngmain) } written one method in 1st form: public void UpdateProgress(int progress) { if (InvokeRequired) Invoke((MethodInvoker)delegate() { trs.progressBar1.Value = progress; }); else trs.progressBar1.Value = progress; } where 'trs' is a instance of form2 declared in form1. No. of times 'a' char is added in single button click event to a string declared called "strngmain". And depending upon each char progress bar status should get incremented in 2nd form. Form2: It contains one progress bar which should increment depending upon the button click event execution: Code in form2: form2_load { progressbar1.show(); } public void go(object param1) { MainForm form = (MainForm)param1; string strng; srtng = ((MainForm)this.Owner).trans_complete; foreach(char c in strng) { form.UpdateProgress(10); Thread.Sleep(10); } } But the above code is not working correctly , progress bar is not incrementing in sync with mainform's button click event code execution. Any help appreciated. Thanks in advance.

    T 1 Reply Last reply
    0
    • G gtag

      There are two issues : 1. My windows application contain many number of controls like, buttons, textboxes,checkboxes etc.. Application is very slow while execution and even for any button click event application hangs for a while(atleast 8 seconds). Used panel and group box but same status. 2.While execution i have to show one progress bar for particular button click event. And need to increment progress bar in sync or simultaneously with button click event execution. Example: (only a part of the code i am writing here in blog): Two forms form1 & form2: on form1 button click event some code is executed. say form1 code: form2 trs = new form2(); btn_click { trs.Show(); trs.Owner = this; trs.go(this); Thread thred = new Thread(new ParameterizedThreadStart(trs.go)); string strngmain = "a"; ....do something........(here actual code executes, while this executes,i want to show the status in progress bar, so while execution i am adding one char to string variable strngmain) } written one method in 1st form: public void UpdateProgress(int progress) { if (InvokeRequired) Invoke((MethodInvoker)delegate() { trs.progressBar1.Value = progress; }); else trs.progressBar1.Value = progress; } where 'trs' is a instance of form2 declared in form1. No. of times 'a' char is added in single button click event to a string declared called "strngmain". And depending upon each char progress bar status should get incremented in 2nd form. Form2: It contains one progress bar which should increment depending upon the button click event execution: Code in form2: form2_load { progressbar1.show(); } public void go(object param1) { MainForm form = (MainForm)param1; string strng; srtng = ((MainForm)this.Owner).trans_complete; foreach(char c in strng) { form.UpdateProgress(10); Thread.Sleep(10); } } But the above code is not working correctly , progress bar is not incrementing in sync with mainform's button click event code execution. Any help appreciated. Thanks in advance.

      T Offline
      T Offline
      Thomas Stockwell
      wrote on last edited by
      #2

      You are going about it in the wrong way. Look into using a BackgroundWorker. It is meant to due computations in the background and relaying progress information to the GUI without freezing the application for awhile.

      Regards, Thomas Stockwell Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Visit my Blog

      G 1 Reply Last reply
      0
      • T Thomas Stockwell

        You are going about it in the wrong way. Look into using a BackgroundWorker. It is meant to due computations in the background and relaying progress information to the GUI without freezing the application for awhile.

        Regards, Thomas Stockwell Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Visit my Blog

        G Offline
        G Offline
        gtag
        wrote on last edited by
        #3

        I am calling many functions in single function which i have written in DoWork event of backgroundworker. I am getting exception while calling multiple functions. exception : "Cross-thread operation not valid: Control 'MainForm' accessed from a thread other than the thread it was created on." Is this backgroundworker supports this kind of requirement of calling multiple functions? Thanks in advance

        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