Calculate estimated time until method completion

Posted on 2006-03-24
Last Modified: 2010-05-18

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()

        ////insert code

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


Question by:annihil8
    LVL 10

    Expert Comment

    Use following code:

    DateTime dt = DateTime.Now;

    //the code you want to check for speed here

    DateTime dt2 = DateTime.Now;

    Timer works in another way,
    Timer is used to raise a timer event after Timer.Interval milliseconds
    LVL 10

    Expert Comment

    or better with:

    DateTime dt = DateTime.Now;

                //the code you want to check for speed here

    LVL 10

    Expert Comment

    forget what i said comes the right one ...sorry :)))

    DateTime dt = DateTime.Now;

    //your code

    LVL 10

    Accepted Solution

    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 this:
    LVL 13

    Expert Comment

    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

    Assuming your 2.0.
    LVL 9

    Expert Comment


    make up your mind!!!  ;-)

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    In one of my recent projects, I was working with IP cameras, I need to take some pictures from the camera and do some processing on it. The first step, was to retrieve the image from camera into Image object. So that it can be displayed or …
    This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now