progressbar in C#

Posted on 2011-10-29
Last Modified: 2013-12-16
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?
Question by:Ikelca
    LVL 9

    Expert Comment

    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).

    Author Comment

    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.

    LVL 9

    Expert Comment

    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.
    LVL 85

    Accepted Solution

    Just set the progressbar to "marquee", which is a built-in "infinite" style.  Move the long tasks to another thread.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    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…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    755 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

    25 Experts available now in Live!

    Get 1:1 Help Now