Sub-millisecond Timing in Windows 95

Posted on 1998-05-15
Last Modified: 2008-02-01
Using Visual C++ in Windows 95,  I am trying to have an event occur exactly every 1 millisecond.  I would acctually like it to occur every 500 microseconds but I don't think I can get that kind of resultion.  The MMTIMER is supposed to support 1ms time intervals, but by events occur later and it is not very precise(running on a P-200).  Is this a possible task??  Can I get events to precisly occur this quickly??
Question by:iasso
LVL 11

Expert Comment

ID: 1250774
First of all, please keep in mind that Win95 is NOT a real-time OS.  Not even remotely.  There is no way to guarentee EXACT timing in your app.  Your threads may be preempted by other apps or the system; interrupts may occur; etc...

With that in mind, the best resolusion is obtained using multimedia timers.  Check the timeSetEvent() function.

Author Comment

ID: 1250775
I know that the multimedia timers give you the best resultion.  My problem is that the resution they give is not good enough.  I'm asking if it is possible.  I know it is not possible using the standard MFC.  Can code be written below the OS level??  Or perhaps if you thunk a 16-bit code appltication you can get better resution than the multimedia timer provide.  I'm not sure how the Win 95 event handling works.  I know when some games load, Alt-tab and other WIN 95 functions do not work.  This is done to increase performance.  Is there a way to give a specific event greater priority??

Expert Comment

ID: 1250776
A specific event, I am not sure of, but processes and threads can be given higher priorities than other processes/threads(or lower) so that they get a bigger slice of the CPU time, so I guess you could probably put this specific task in its own thread, pump its thread priority to the highest, and give its process a slightly raised priority(unless you think its really mission critical, then you could really boost that up too) and get a bit better timing.
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

LVL 10

Accepted Solution

RONSLOW earned 100 total points
ID: 1250777
thread priority can be changed without your consent by the OS.  So that won't help.

The multimedia timers are not MFC .. they ARE O/S calls.

If you are running on a pentium, then there are routines for accurate timing (I think i can dig some out for you).

Also, there are the profiling API's that may help.

Also, if you really want to be accurate, you should probably write a VxD instead .. that way you can avoid being interrupted partway thru.

I'll see what extra info on these I can dig up for you.

LVL 10

Expert Comment

ID: 1250778
The August 96 Windows Developers Journal has an article and source code on "A More Accurate Timing Tool"

You can get the source code (not sure about the article) from

The code is assembler.

LVL 10

Expert Comment

ID: 1250779
Look at QueryPerformanceCounter and QueryPerformanceResolution

The docs say ...

High-Resolution Timer

A counter is a general term used in programming to refer to an incrementing variable. Some systems include a high-resolution performance counter that provides high-resolution elapsed times.

If a high-resolution performance counter exists on the system, the QueryPerformanceFrequency function can be used to express the frequency, in counts per second. The value of the count is processor dependent. On some processors, for example, the count might be the cycle rate of the processor clock.

The QueryPerformanceCounter function retrieves the current value of the high-resolution performance counter (if one exists on the system). By calling this function at the beginning and end of a section of code, an application essentially uses the counter as a high-resolution timer. For example, suppose that QueryPerformanceFrequency indicates that the frequency of the high-resolution performance counter is 50,000 counts per second. If the application calls QueryPerformanceCounter immediately before and immediately after the section of code to be timed, the counter values might be 1500 counts and 3500 counts, respectively. These values would indicate that .04 seconds (2000 counts) elapsed while the code executed.

LVL 10

Expert Comment

ID: 1250780
But as said before, if you need accurate timing, then it is best to do time-critical code in a VxD where you have some (better) control over your interrupts.

From a VxD you can call certainly call Get_System_Time (but that is only to the millisecond) .. I am not sure what other timers are or are not available in a VxD (I only have one that required millsecond timing, so Get_System_Time is ok).

LVL 10

Expert Comment

ID: 1250781
Also ,check out and look for uclock.c which does micro-second timings.


Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C++ vs C compilers 13 160
How to issue a linefeed, pause, and clear screen in UNIX enviroment 3 74
Arduino EDI - Programming language 3 103
Resolve Dependency Issues 4 79
This tutorial is posted by Aaron Wojnowski, administrator at  To view more iPhone tutorials, visit This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

860 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