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
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
or better with:
DateTime dt = DateTime.Now;
//the code you want to check for speed here
MessageBox(DateTime.Now.Su btract(dt) );
DateTime dt = DateTime.Now;
//the code you want to check for speed here
MessageBox(DateTime.Now.Su
forget what i said before..now comes the right one ...sorry :)))
DateTime dt = DateTime.Now;
//your code
MessageBox.Show(((TimeSpan )DateTime. Now.Subtra ct(dt)).Mi lliseconds .ToString( ));
DateTime dt = DateTime.Now;
//your code
MessageBox.Show(((TimeSpan
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
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.
.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.
make up your mind!!! ;-)
that's right, though, you want the TotalMilliseconds.
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