WM_TIMER message delay

Posted on 2004-11-07
Last Modified: 2013-12-03
WM_TIMER message handler in my program is called with significant delay - about 100-200 ms. Usually it's precision is 20-30 ms. For example, if I use

SetTimer(TIMER_ID, 1000, NULL);       // in CWnd-deriver class

OnTimer function may be called with 1100-1200 ms intervals. What may be a reason for this? This program worked number of years without problems.
Question by:AlexFM
    LVL 48

    Author Comment

    Additional information:
    I made small MFC test program which prints current time from WM_TIMER message handler. It works OK. When it runs together with the program which has timer delay, it works also. So, some changes made in the program give this result. What is a reason - too large program, long message map, something else?
    I can replace WM_TIMER with multimedia timer, but it is interesting why this happens.
    LVL 55

    Expert Comment

    by:Jaime Olivares
    I haven't noticed that problem before, but, what happens if you use non-MFC SetTimer function?
    LVL 17

    Accepted Solution

    Maybe this is an answer

    The DispatchMessage Windows function sends a WM_TIMER message when no other messages are in the application's message queue.

    LVL 16

    Expert Comment

    More exactly:
    The WM_TIMER message is a low-priority message. The GetMessage and PeekMessage functions post this message only when no other higher-priority messages are in the thread's message queue.

    But to get delays of more than 1 sec, you should have a significantly amount of high-priority messages in the queue (which seems unlikely to occur).
    LVL 48

    Author Comment

    mokule's comment gives me right direction, so he gets these points.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
    What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now