• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1190
  • Last Modified:

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
0
annihil8
Asked:
annihil8
  • 4
1 Solution
 
dkloeckCommented:
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
0
 
dkloeckCommented:
or better with:

DateTime dt = DateTime.Now;

            //the code you want to check for speed here

MessageBox(DateTime.Now.Subtract(dt));
0
 
dkloeckCommented:
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());
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
dkloeckCommented:
ups..another thing i forgot (it must be to early in the morning lol )

with Milliseconds you only get the milliseconds.. that means, if it takes 1 second and 33 milliseconds, it will show
"33", so you should use TotalMilliseconds instead..like this:
MessageBox.Show(((TimeSpan)DateTime.Now.Subtract(dt)).TotalMilliseconds.ToString());
0
 
devsolnsCommented:
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.
0
 
msdixonCommented:
dkloeck,

make up your mind!!!  ;-)

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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now