progressbar in C#

hi guys,

Im trying to create a progressbar
i tried timer option, it worked but didnt really work as I wanted, because it just keeps iterating until stop.
i want a progressbar that gradually grew up to max value.
the issue now is that the code I need progressbar for is a simple adding printer method.
and how long it takes to finish is up to network.

how can I make a progressbar in this case?
any example?
Who is Participating?
Mike TomlinsonMiddle School Assistant TeacherCommented:
Just set the progressbar to "marquee", which is a built-in "infinite" style.  Move the long tasks to another thread.
Ehm, from my printer experience, you won't be able to get that time length. So you won't be able to calculate where it is up to.

That's why now some programmers use infinite progress bar which doesn't show a progress but only a running process (when time to accomplish is unknown or no data can be used to establish a maximum).
IkelcaAuthor Commented:
well, in my case, the time period of adding a printer varies so i still can see the difference,
and i did use timer to create infinite loop progressbar. but i don't really like it.
it works sometime, and sometimes only runs half or something.

in addition, adding a printer is just an example, there are other stuff such as authentication through WLAN in AD and so on. all take sometimes.

also, i have tried using a 2nd background worker, but it seems vc2010 does not allow me adding 2nd.

From your other usage examples, I see that no definitive time length can be calculated, because (as you also say) it varies through time.

So, in this case, the only way is to advice the user that your program is not crashed and is still executing the task. Otherwise, you could calculate times and store it. With this information, you can average them and use that number as your maximum. So the progress bar would always ends near by the end (either a little before or after, if your lucky, on it). This can be tricky though if erroneous data comes in. This could also be detected, but can more trickier.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.