Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to improve timing in vb
Message
From
21/09/2000 17:09:44
 
 
To
21/09/2000 12:57:13
General information
Forum:
Visual Basic
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00418957
Message ID:
00419389
Views:
19
>Found this one:
>
>Private Declare Function GetTickCount Lib "kernel32" () As Long

Is not going to do it for you; in all probability, you'll need to use a high-performance counter, which is processor dependent as to exact resoultion. You'll need to use QueryPerformanceFrequency() to determine the counter interval, and QueryPerformanceCounter() to examine the current state of the high-performance counter. Both work with a 64 bit LARGE_INTEGER, qnd not all systems support the high-performance counter. You need to query the frequencyeach time you run your app; the frequency is processor and OS dependent, and may not be altered at runtime.

You may be able to use the Win32API timer-related functions. You can alter the frequency of updates to the system clock, allowing for a finer-resolution 'tick' through the SetSystemTimeAdjustment() call, and then rely on a timer. The precision of time adjustment specifications is in units of 100ns; it requires NT or Win2K, and requires that your process is granted the system-time privilege SE_SYSTEMTIME_NAME, ordinarily requiring a call to AdjustTokenPrivileges() to enable. The basic p_code:

Call OpenProcessToken(GetActiveProcess(),TOKEN_ALL_ACCESS,pTokenHandle)
Call AdjustTokenPrivileges() to enable SE_SYSTEMTIME_NAME
Call GetSystemTimeAdjustment() to get current settings
Call SetSystemTimeAdjustment() to the desired value
Call AdjustTokenPrivileges() to reset the SE_SYSTEMTIME_NAME state
Do your interval-sensitive stuff
Call AdjustTokenPrivileges() to enable SE_SYSTEMTIME_NAME
Call SetSystemTimeAdjustment() back to the initial state
Call AdjustTokenPrivileges() to reset the SE_SYSTEMTIME_NAME state
Call CloseHandle(pTokenHandle) to release the process token handle

NB: this might affect the system's time of day adjustments and display.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform