Hi everyone,
I am wondering how to measure an application Loading Time
when user starts the process,application instance so that I can show a progress bar or something which informs users what's happening when application is loading or how much application loading is completed.
I mean what if I want to show current progress with a progress bar so I think I am able to define the the current process with numbers so I can increase the Value
property of an ProgressBar
control.
Thanks in advance.
Sincerely.
Edit :
What I've found as a solution is :
You can use System.Diagnostics.Stopwatch for measuring time. Place a call to the method Start at the beginning of the constructor of the form.
After a form has been displayed, typically the Application.Idle Event rises. Thus, you could call the Stop method in a handler for this event. But you should check that this Event indeed does rise, e.g. by using System.Diagnostics.Debug.WriteLine, together with the tool DebugView from sysinternals.com.
So we can use System.Diagnostics.StopWatch
like this :
using System;
using System.Diagnostics;
using System.Threading;
class Program
{
static void Main(string[] args)
{
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
Thread.Sleep(10000);
stopWatch.Stop();
// Get the elapsed time as a TimeSpan value.
TimeSpan ts = stopWatch.Elapsed;
// Format and display the TimeSpan value.
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes, ts.Seconds,
ts.Milliseconds / 10);
Console.WriteLine(elapsedTime, "RunTime");
}
}
And then when Idle event fires, I would be able to find the loading time and show it on the progress bar but progress bar would not show the accurate percentage of loading time, I think.