WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Time - Timer and Date Functions
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Fractional TimeDelay Problem


Question:

I'm trying to prevent log file overwrites when using INI files (time as key) by delaying operations by .01. For some reason, this seems to add an excessive delay to the running program. This code seems to indicate that a delay time of .01 is invalid?
timeToDelay = .01
estimate = timeToDelay * 100

startTime = TimeYmdHms()
For counter = 1 To 100
TimeDelay(timeToDelay)
Next
difference = TimeDiffSecs(TimeYmdHms(), startTime)

Message("Finished with Delay = %timeToDelay%", "Should be %estimate%. Actual = %difference%")
Am I using this function wrong?

Answer:

If you make your time Delay a negative number, you will get the result you are looking for.
timeToDelay = -0.01
estimate = timeToDelay * 100

startTime = TimeYmdHms()
For counter = 1 To 100
TimeDelay(timeToDelay)
Next
difference = TimeDiffSecs(TimeYmdHms(), startTime)

Message("Finished with Delay = %timeToDelay%", "Should be %estimate%. Actual = %difference%")
The timedelay function gives up processing time and asks the system to resume the function in the desired amount of time. So during the interim the system asks all the other programs in the system how they are doing, then checks to see if the time elapsed yet, and if so, resumes WinBatch. For small amounts of time (like 1/100 of a sec) it might take a bit longer than 1/100th of a second to service all the other applications and get back to WinBatch.

Specifying negative numbers uses a different, more accurate algorithm BUT does not give up much CPU time to other appplications. If you are waiting for ini files to be updated...Did you try

iniwritepvt("","","",inifilename)
which is supposed to do that?
Article ID:   W16727
File Created: 2005:02:18:12:22:04
Last Updated: 2005:02:18:12:22:04