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
Solved

Problem with the message pump hanging

Posted on 1997-08-29
3
545 Views
Last Modified: 2013-12-03
I have a very strange problem. I am working with an application that
uses many different threads. At some point I seem to get into a
situation where there are no threads to pump the message queue. The code
in question create an event and posts a WM_USER style message to the
window queue and then does a WaitForSingleObject(). The message pump is
supposed to see the message and post the event to cause the wait to
finish. The problem appears to be that the thread that is supposed to be
pumping is the one waiting. I tried using WaitForMultipleObjects() and
dispatching the messages myself but that also doesn't seem to work.
I am looking for any other clues that prople might be able to give me.

The purpose of this logic is to insure that the message queue is empty
before killing the window. The processing must be synchonous. I don't think I can allow the window to
go down asynchronously
0
Comment
Question by:sasjaa
  • 2
3 Comments
 
LVL 3

Expert Comment

by:vinniew
ID: 1405120
You shouldn't do it like that.  It's much easier to control if you use a global flag (bool) variable to control things like that.  As for checking the queue before you 'kill' the process, I think you should use Mutexes (see CreateMutex) instead of events.  The event processing is what's causing problems.  You can use mutexes in the same way, but they work inside the main process.

In any case, I can't be sure about this solution without seeing code or without a general outline of what's happening, so post more if you need more.
0
 

Author Comment

by:sasjaa
ID: 1405121
I don't see how a Mutex can help. A window destroy request comes in and we need to make sure that there are no pending messages in the queue for this window before we delete the object. Microsoft documentation clearly states that a CEvent should be used if we must wait for something else to happen before continuing. The problem is that we are waiting on messages and there seems to be nothing to process the messages.
0
 
LVL 3

Accepted Solution

by:
vinniew earned 200 total points
ID: 1405122
You could start up another message 'pump within a pump' to handle the wm_destroy message.  Use the while.. peekmessage.. sendmessage... loop in the handler for wm_destroy.  That would definitely empty the queue.

V
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

829 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