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

DeleteTimerQueueTimer Hangs with small intervals

Posted on 2008-06-14
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
  • 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 500 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.
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.


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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

840 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