Solved

Coding a Progress Bar

Posted on 2013-11-03
6
614 Views
Last Modified: 2013-12-07
Hello,
I have a c# application which reads through a transaction file processing each record within the transaction (could be 200 records per transaction). I have a Driver.cs program reading through each of the transactions from sequence 1 to last sequence. Some of the transactions will have an input requirement (indicated by a flag on the transaction itself) and when such a flag is encountered a call is made to an new form "InputForm1.cs" to take in the required input. These inputs are the only user interface in processing the transactions. I need to show a "Progress bar"  to indicate to users that application is processing (especially when it in processing non input transactions).

I have tried putting a progress bar into the InputForm1 form and then calling the InputForm1 for the non-input transactions  as well as input transactions and for the non input transactions, displaying the progress bar, but this just produces a lot of flicker.

Appreciate if anyone can advise on the best method of displaying a progress bar in these circumstances that will give a seamless display of % progress when non input transactions are being processed.

thanks
Pat
0
Comment
Question by:pclarke7
  • 3
  • 2
6 Comments
 
LVL 2

Assisted Solution

by:Pavel_Kudishin
Pavel_Kudishin earned 334 total points
ID: 39619980
You need to process your transaction in separate background thread (e.g. use BackgroundWorker class which can reporting progress to UI. See usage example by the previous link
0
 

Author Comment

by:pclarke7
ID: 39620024
Hi Pavel,
thanks for your comment. I can't see how this will solve the issue. If, for example, my 2nd and 100th Sequence within the transaction require an input. The the InputForm1 will be called initially on 2nd transaction and will be closed until until the 100th transaction - which could be a 30 second delay. In this instance how and where can I keep user informed of progress.

regards
Pat
0
 
LVL 23

Assisted Solution

by:Michael74
Michael74 earned 166 total points
ID: 39620701
The easiest method would be to display the progress bar with continuous display. This way you do not need to worry about updating the progress bar.

here is a good article on progress bars

http://www.codeproject.com/Articles/449594/Progress-Bars-Threads-Windows-Forms-and-You

Michael
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 2

Accepted Solution

by:
Pavel_Kudishin earned 334 total points
ID: 39620743
If you are developing ASP.NET application then use timer and ajax on you page to request progress from server and to update progress bar on the page.

Also with ajax request from the server transaction's queue which required input from user and display on the page input controls for user.

Transaction on the server need to be processed with custom windows service which builds transaction queue from transactions which require user input
0
 

Author Comment

by:pclarke7
ID: 39628812
I have tried using a background worker to run the progressBar however I am not getting beyond 1% in the following example.  In the Form1_Load I have an iteration inside which I want to display the ProgressBar. Appreciate if someone can point out where I am going wrong with this logic.

Pat



namespace WindowsFormsApplication1
{

    public partial class Form1 : Form
    {
        BackgroundWorker bgw = new BackgroundWorker();
        float tot1=100;
        float cnt1=0;
        float rslt = 0;
        int percents = 0;
        public Form1()
        {
            InitializeComponent();
            label1.Text = "";
            label2.Text = "";
        }


        void bgw_DoWork(object sender, DoWorkEventArgs e)
        {
             {
                System.Threading.Thread.Sleep(500);
                rslt = ((cnt1 / tot1) * 100);
                percents = Convert.ToInt32(rslt);
                bgw.ReportProgress(percents, cnt1);
             }
        }

        void bgw_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            progressBar1.Value = e.ProgressPercentage;
            label1.Text = String.Format("Progress: {0} %", e.ProgressPercentage);
            label2.Text = String.Format("Total items transfered: {0}", e.UserState);
        }

        void bgw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            //do the code when bgv completes its work
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            for (cnt1 = 0; cnt1 <= tot1; cnt1++) //some number (total)
            {
                bgw.DoWork += new DoWorkEventHandler(bgw_DoWork);
                bgw.ProgressChanged += new ProgressChangedEventHandler(bgw_ProgressChanged);
                bgw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgw_RunWorkerCompleted);
                bgw.WorkerReportsProgress = true;
                if (!bgw.IsBusy)
                {
                    bgw.RunWorkerAsync();
                }
            }
        }

        private void progressBar1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {

        }
      }
    }
0
 

Author Closing Comment

by:pclarke7
ID: 39703018
Thanks for your help. Working nicely now
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now