Solved

Progress Bar

Posted on 2009-07-06
4
571 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 175 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 150 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 175 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
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…

705 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