DeleteTimerQueueTimer Hangs with small intervals

Posted on 2008-06-14
Medium Priority
Last Modified: 2013-11-20
I have an MFC app playing DirectX audio while aQueue timer is running.  I start the timer when the audio starts, and stop the timer when the audio stops.

The calls to start and stop the timer are standard:

void CFormView3::StopTimer()
      DeleteTimerQueueTimer(NULL, m_timerHandle, NULL);
      CloseHandle (m_timerHandle);

void CFormView3::StartTimer()
      // create the timer
      BOOL success = ::CreateTimerQueueTimer(

Interestingly, if I make the interval higher (change 50 to 2000) it doesn't hang, but then I get an error when I call CloseHandle.

I am guessing this has something to do with the way threads are handled, but I don't have much experience controlling threads.

Question by:dparkes
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 19

Expert Comment

ID: 21801585
1) Try to call DeleteTimerQueueTimer() with the third parameter not null.
DeleteTimerQueueTimer(NULL, m_timerHandle, INVALID_HANDLE_VALUE);

2) Are you sure that you have to call CloseHandle(m_timerHandle)? In MSDN documentation I found no topic saying to call it.

3) Did you perform long operation in TimerProc()?


Author Comment

ID: 21818740

I tried using INVALID_HANDLE_VALUE, and the first time it got past DeleteQueueTimer, but after that it locked up every time.  I'm not sure if this was just a coincidence or not.

Regarding TimerProc, I do not know exactly what you mean by performing a long operation.  Perhaps I declared the TimerProc function incorrectly?

To be more precise, I have this in a file called FormView.cpp directly below my StopTimer function:

void CALLBACK TimerProc(void* lpParametar, BOOLEAN TimerOrWaitFired)
    CFormView3* obj = (CFormView3*) lpParametar;

And I have this in the same file above CFormView3::CFormView3(CWnd* pParent /*=NULL*/):

void CALLBACK TimerProc(void*, BOOLEAN);

I really was not sure how to declare the callback function.  Unfortunately I do this in my spare time so sorry for the delay getting back.
LVL 19

Accepted Solution

alb66 earned 2000 total points
ID: 21819782
>>>>>I do not know exactly what you mean by performing a long operation.

What do you do in obj->QueueTimerHandler() ? It should do only few operations.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 21827506
That must be it, it does a lot.  Looks like I mistakenly ignored that little caveat in the QueueTimerHandler specifications.  I set a couple variables, but I also do an Invalidate() which refreshes a graphically intensive control I made.

I'm almost certain that's the cause of the problem now, I really appreciate your help.

I don't mean to piggy back a supplemental question, but really quick, do you know how I might be able to move that Invalidate function outside QueueTimerHandler?  A message handler maybe??
LVL 19

Expert Comment

ID: 21828897
Invalidate() simply marks a client area for painting when the next WM_PAINT message occurs. The important is that you havn't call UpdateWindow(), that perform the redrawing immediatly.

You can try to redraw only the parts of the graphic control that are really changed and not all the control. See InvalidateRect() and InvalidateRgn().

Anyway, post a message to window instead af calling directly a function, is always a good solution

Author Comment

ID: 21831470
Yes, I also have more going on than the painting too.  Actually I'm sending instructions to a USB device as well.  I should use a message handler for that too.  Big mistakes I didn't even notice.  Thanks again.
LVL 19

Expert Comment

ID: 21831490
You're welcome.

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

770 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