[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

DeleteTimerQueueTimer Hangs with small intervals

Posted on 2008-06-14
7
Medium Priority
?
1,411 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
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()?


0
 
LVL 1

Author Comment

by:dparkes
ID: 21818740
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 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.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

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

Expert Comment

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

Author Comment

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

Expert Comment

by:alb66
ID: 21831490
You're welcome.
0

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Screencast - Getting to Know the Pipeline
Suggested Courses

810 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