views:

1389

answers:

5

how do i calculate the loading percentage of my C# application. i want to show a splash screen with a progress bar showing percentage of application loaded.

Is there any standard method\library for that or i will have to just update the progress bar value at different points in my form load code.

Or can any gimme a tutorial on application preloaders

+2  A: 

Well, in any case you need a fairly accurate guess at how long your individual steps take. Only then can you give an actually meaningful progress bar. You can approximate it by dividing your loading process into several steps you assume to be roughly equal in time and calculate progress as you finish those steps.

An alternative would be not to show a progress bar but rather a series of loading steps, represented either by text or graphically. I think KDE does this on startup. That way you show progress but avoid the user's expectations towards a progress bar (which works best if the progress bar is either linearly progressing or accelerating. If it frequently stops and jumps it just creates the impression of a very slow process).

Another option would be to eliminate the splash screen entirely by trying to make program startup fast and loading what you need at runtime. This may or may not be an option for you or your program but it can show pretty significant improvements in startup time and overall impression of program speed.

Joey
so all i can get with these aanswers is that progress bar is actually our own logical calculation not like the code that was supposed to be loaded in memory has been loaded X percent.
Junaid Saeed
+1  A: 

First of all the Splash screen is shown to give user an illusion that program has started and they will be handled control at any moment.

Secondly if you want to show the progress bar then you need to accurately calculate the number of tasks you perform. Then show the label loading xxxxxx....... and increment progress bar after completion of every item.

As for the question of optimizing starting up time it mainly depends upon the function of your application.

Suppose you app is a PIM then you may load the events and tasks for today and show it to the user quickly and then start loading other data.

I once had an application where I had to show the object hierarchy using Treeview each node could have unlimited number of items. I loaded the top level objects and displayed then in the tree view and put marker (actually I put * in tag of the node, which I learned from some .net book or article I had read long ago but remembered) when use clicked on the node I loaded the immediate children.

TheVillageIdiot
+1  A: 

Probably the easiest way to do this is to create an instance of your splash form at the beginning of your startup form's Load event. In the splash form, expose its ProgressBar as a public property. After creating the splash form, set its ProgressBar's Maximum property to the number of discrete steps that you can identify in the Load event code, then show it by calling its .Show() method (not .ShowDialog(), of course).

As each step in the Load event completes, you just increment the public ProgressBar's Value property. When all steps have completed, close the splash form and dispose it.

This may or may not work properly, because if your startup form contains a large number of controls, then a good percentage of the total loadup time will actually be spent in the form's constructor, which will be called before the Load event. It might be best to move all of your initialization code into the constructor, and create and Show the splash screen from there.

MusiGenesis
+3  A: 

The first time user starts your application, assume it will take 10 seconds and show progressbar counting down those 10 seconds. Once the application is loaded, save somewhere on user's computer actual time it took to load your application. Next time user loads your application, use saved time instead of your original 10 seconds.

This is simple and obvious concept. User doesn't care what parts of the application are loading, he cares how long it's going to take and he wants to see countdown.

lubos hasko
+1 for not being the worst idea I've ever heard. :)
MusiGenesis
and you deserve some kind of badge for upvoting competing answer :)
lubos hasko
A: 

A Pretty Good Splash Screen or
Splash Screen

SwDevMan81