Link to home
Start Free TrialLog in
Avatar of annihil8
annihil8

asked on

Calculate estimated time until method completion

Hi,

I'm trying to calculate an estimated completion time of a method.
This means that when there are 10 inserts into the database the estimated time should popup after the first insert. The estimated time is calculated by the first insert. (9 times the first insert time).

I've tried it with a timer like

private _time;
private save_entries()
{

     timer1.enabled=true;
        ////insert code
    timer1.enabled=false;
}

the problem with this code is that the timer doesn't start in a method, only when a method is fully completed. So the timerevent is never executed. when you debug and you comment the timer1.Enabled= false line, you noticed that the debugger starts in the event after method completion

Does anybody know how to solve this issue?

I'm working in c# on a windows mobile 5.0 PDA with Compact framework 2.0 installed

Grtz

Annihil8
Avatar of dkloeck
dkloeck
Flag of Spain image

Use following code:


DateTime dt = DateTime.Now;

//the code you want to check for speed here

DateTime dt2 = DateTime.Now;
dt2.Subtract(dt);
MessageBox(dt2.Millisecond);

Timer works in another way,
Timer is used to raise a timer event after Timer.Interval milliseconds
or better with:

DateTime dt = DateTime.Now;

            //the code you want to check for speed here

MessageBox(DateTime.Now.Subtract(dt));
forget what i said before..now comes the right one ...sorry :)))

DateTime dt = DateTime.Now;

//your code

MessageBox.Show(((TimeSpan)DateTime.Now.Subtract(dt)).Milliseconds.ToString());
ASKER CERTIFIED SOLUTION
Avatar of dkloeck
dkloeck
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of devsolns
devsolns

You need to explorer all of the classes in the System.Diagnostics namespace.  They have specific classes meant to do what you want.  They included many performance counters and a StopWatch class.

.NET Framework Class Library  
Stopwatch Class  

Provides a set of methods and properties that you can use to accurately measure elapsed time.

Namespace: System.Diagnostics


http://msdn2.microsoft.com/en-us/library/system.diagnostics.stopwatch(VS.80).aspx


Assuming your 2.0.
dkloeck,

make up your mind!!!  ;-)

that's right, though, you want the TotalMilliseconds.