Calculating ETA from only a percentage of progress

Ah hello.

I have a class function.  That function starts a thread, whose sole purpose is to call an SDK function.  That SDK function reports progress back via a special CALLBACK function.  I would like to be able to report to the user an estimate of how long the SDK function will take to complete.

Now then.

All that I get back from the SDK is a double representing the progress so far; between 0 and 1.0.  Not very useful.  So I put some thought in, and came up with the idea of having an independent timer running alongside the SDK CALLBACK.  Setting the timer up to send a message to me every one second, I could wait until, say, two seconds have passed, then look at how much progress has been made in the CALLBACK.  I could then base calculations on the time remaining around the fact that on average, ( progress made in two seconds / 2 ) % progress is made every one second.  And go from there...

This sounds a bit messy though.  I would need some sort of member variable holding the number of seconds passed as reported by my timer, that the CALLBACK also has access to.  Then I would need to protect access to that variable possibly...

Not a serious problem, but I am guessing that someone has come across this kind of issue before.

Any better ideas ?

TIA
LVL 19
mrwad99Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
Sounds reasonable to me.  
How reliable is the progress report from the SDK function?
<  0 to 0.5 takes 10 seconds, 0.5 to 1.0 takes 100 seconds !!  Think M$ explorers guesstimate of duration left, I wish I had £1 for each time it says 5 seconds to complete and that is shown for x minutes>

(Remember the two pocesses aren't synchronised but that shouldn't be a problem)
krbatgeCommented:
I would probably use GetTickCount() rather than a timer (not because of more accurate timing, just to make things simpler)...

e.g.

    // get starting tick count and save in member variable
    m_dwStart = GetTickCount();
    //start your process

then in progress callback function...

    DWORD dwDuration = GetTickCount() - m_dwStart;
    // esitmate time left
    DWORD dwTimeLeft = (dwDuration/progress -dwDuration);


of course your time estimate is now in milliseconds which is far too precise, but just round to the nearest second...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mahesh1402IT ProfessionalCommented:
>>I would need some sort of member variable holding the number of seconds passed as reported

if you can use shared MFC/ATL classes have a look at 'CFileTime' class...

EVEN if  class provides methods for managing the date and time values associated with a file You can use it to calculate difference between two times in MiliSeconds / Seconds

eg. have look at CFileTime::Millisecond  static data member.. refer this sample...

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

MAHESH

mrwad99Author Commented:
Thanks all :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.