?
Solved

Coding a Progress Bar

Posted on 2013-11-03
6
Medium Priority
?
631 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 2

Assisted Solution

by:Pavel_Kudishin
Pavel_Kudishin earned 1002 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:Michael Fowler
Michael Fowler earned 498 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
Understanding Linux Permissions

Linux for beginners: How to view the permissions associated with files and directories and also how you can change them.

 
LVL 2

Accepted Solution

by:
Pavel_Kudishin earned 1002 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

Stack Overflow Podcast - Developer Story

Welcome to the Stack Overflow podcast recorded Thursday July 20 at Stack Overflow Headquearters in NYC. Your hosts today are podcast regulars Jay Hanlon, David Fullerton, and Ilana Yitzhaki, plus the quite irregular Matt Sherman (Stack Overflow Engineering Manager extraordinaire)

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

741 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