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