Image of Navigational Panel mapped to Contents / Home / Search Precise Delays
Tech Support Question

Image of Line Break

Q. I have an animation routine that is moving too fast and wanted to put a non machine-specific delay in. I could use a timer, and some very ugly code, but I thought I would do something like this with the API function

  GetTickCount()...
  TicksTarget = GetTickCount() + 100         ' Wait 100 ticks
  while (GetTickCount() < TicksTarget) : Wend

This produces a delay much longer than 100 ticks. Can you tell me why I'm not getting the results I expected?

From: Larry Johnson
Email: larryj@voyageronline.net

A. GetTickCount is a cool API call, that usually is so uncomplicated way to achieve the sort of effect you are after. There are a couple of things to consider when using GetTickCount. The first is that in a multi-tasking operating system your code only executes when another process is not hogging the system. If you have another process running which is hogging system time then your VB app may not get a chance to call GetTickCount, until more than 100 ticks have elapsed.

The other consideration is that the frequency with which VB is given processing time will vary, dependant upon your operating system. For example, under Windows 3.11 your application will be given processing time at most every 55 ticks, under Windows 95 this drops to a mere 13 ticks.

Under normal circumstances running this code under Windows 3.11 this code should execute for 110 ticks (2 * 55 ticks). However, if something else is hogging processing time, your app may not get a chance to call GetTickCount until much later.

You might want to consider any VBXs you are using or the JET engine as possible sources of the processing delay. The JET engine likes to use time detected as unused to run what it classes as background processing, this would involve cleaning up temporary tables, memory de-allocation and other such wonders.

Essentially, what I am saying is that you are using appropriate code which is being prevented from working by an outside source. Have a close look at what processes are running and try the same code with minimal other processes, then add them one by one until you detect which one is causing the problem. You might also want to take this approach with parts of your project, remove some of your VBXs or database engine activities. And then re-add them one by one. It's laborious but it may just help you determine what is causing the problem.


Image of Arrow to Previous Article Image of Arrow to Next Article

[TECH SUPPORT TOC]
Image of Line Break
[HOME] [TABLE OF CONTENTS] [SEARCH]