?
Solved

Progress Bar

Posted on 2009-07-06
4
Medium Priority
?
572 Views
Last Modified: 2012-05-07
In a section of my program i am having it pull lines from a text file and place them as a comma separated list in an array.  
this is all done in a for loop.  is there an easy way that i can add a progress bar to my program to let the user see how far along the process is?
0
Comment
Question by:cotj73
[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
4 Comments
 
LVL 20

Accepted Solution

by:
ddayx10 earned 525 total points
ID: 24791470
Whew, interresting question, only way I can see to do it is with AJAX and it would only be as accurrate as the network traffic allowed.... I think I would consider just faking it. Obviously any of these solutins are going to need AJAX (you are likely already using it or you wouldn't be asking about this).

A) Just use a progress bar made of an animated gif that runs a continual loop until you get your results back.

B) Do some testing and findout the avg time it takes to run with N lines, then use the count of the loop to create an approximated timer. Could be actual countdown, or use a little math to fill a box with pixels relative to the time needed...

C) Just tell'em it's gonna take awhile (depending on their input) and to be patient :)

I'll be interrested to see if anyone comes up with a good answer for this!
0
 
LVL 26

Assisted Solution

by:Anurag Thakur
Anurag Thakur earned 450 total points
ID: 24791801
you cannot find the time required to read the text out of files and then add them to an array easily and the best approach will be to just create a processing image and show so that the user knows that the process is going on and they will have to wait for a while
0
 
LVL 5

Assisted Solution

by:Pablissimo
Pablissimo earned 525 total points
ID: 24792772
Assuming you're using a StreamReader, and you're using ReadLine, you can query the StreamReader's BaseStream property for a Stream object, use that object's Length and Position properties to get how far through the file you are. Set your progress bar maximum to be the length of the file (say), and update the progress bar value to equal your reader.BaseStream.Position calling Application.DoEvents as required to update the UI.

This will only be an approximation, and may not work every time since buffering'll mean that Position jumps a bit (many calls to ReadLine might yield the same Position property value) but it might be sufficient if you have a large file.

StreamReader myReader = new StreamReader( @"C:\TheTextFile.txt" );
 
long lenBytes = myReader.BaseStream.Length;
 
while ( !myReader.EndOfStream )
{
  string theLine = myReader.ReadLine();
 
  // Do whatever parsing you're doing
 
  // Replace me with progress bar update code
  Console.WriteLine( "{0:p2} complete", ( (float) myReader.BaseStream.Position ) / lenBytes );
}

Open in new window

0
 
LVL 1

Author Comment

by:cotj73
ID: 24851738
I endedup using the progress bar function built into Visual Studio. you can set a max Value and increase it.  allowing an animation for progress
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

801 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