Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

DeleteTimerQueueTimer Hangs with small intervals

Posted on 2008-06-14
7
Medium Priority
?
1,388 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
[X]
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
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
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!

 
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

609 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