We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Calculate estimated time until method completion

annihil8
annihil8 asked
on
Medium Priority
1,216 Views
Last Modified: 2010-05-18
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
Comment
Watch Question

Commented:
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

Commented:
or better with:

DateTime dt = DateTime.Now;

            //the code you want to check for speed here

MessageBox(DateTime.Now.Subtract(dt));

Commented:
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());
Commented:
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());

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Commented:
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.

Commented:
dkloeck,

make up your mind!!!  ;-)

that's right, though, you want the TotalMilliseconds.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.