Solved

DeleteTimerQueueTimer Hangs with small intervals

Posted on 2008-06-14
7
1,303 Views
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(
            &m_timerHandle,
            NULL,
            TimerProc,
            this,
            0,
            50,
            WT_EXECUTEINTIMERTHREAD);
}


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.

0
Comment
Question by:dparkes
  • 4
  • 3
7 Comments
 
LVL 19

Expert Comment

by:alb66
Comment Utility
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()?


0
 
LVL 1

Author Comment

by:dparkes
Comment Utility
Alb66,

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;
    obj->QueueTimerHandler();
    }

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.
0
 
LVL 19

Accepted Solution

by:
alb66 earned 500 total points
Comment Utility
>>>>>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.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 1

Author Comment

by:dparkes
Comment Utility
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??
0
 
LVL 19

Expert Comment

by:alb66
Comment Utility
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
0
 
LVL 1

Author Comment

by:dparkes
Comment Utility
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.
0
 
LVL 19

Expert Comment

by:alb66
Comment Utility
You're welcome.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

728 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

8 Experts available now in Live!

Get 1:1 Help Now