::WaitForSingleObject blocking message pump or not ?

Hi,

if I have an appliaction with a window, if I call WaitForSingleObject 
does it block the window message pump ?
0
richom.v (84)
4/1/2007 1:47:01 PM
vc.mfc 33608 articles. 0 followers. Follow

13 Replies
1412 Views

Similar Articles

[PageSpeed] 14

"Vincent RICHOMME" <richom.v@free.fr> wrote in message 
news:460fb71d$0$19143$426a34cc@news.free.fr...
> Hi,
>
> if I have an appliaction with a window, if I call WaitForSingleObject does 
> it block the window message pump ?

Oh yes, try it:  call WaitForSingleObject() and then try dragging your 
window.  It will not move showing the message pump is stuck.

-- David 


0
dc2983 (3206)
4/1/2007 2:06:38 PM
David Ching a �crit :
> "Vincent RICHOMME" <richom.v@free.fr> wrote in message 
> news:460fb71d$0$19143$426a34cc@news.free.fr...
>> Hi,
>>
>> if I have an appliaction with a window, if I call WaitForSingleObject does 
>> it block the window message pump ?
> 
> Oh yes, try it:  call WaitForSingleObject() and then try dragging your 
> window.  It will not move showing the message pump is stuck.
> 
> -- David 
> 
> 
How can I fix this ?
0
richom.v (84)
4/1/2007 2:39:07 PM
"Vincent RICHOMME" <richom.v@free.fr> wrote in message 
news:460fc34e$0$20527$426a34cc@news.free.fr...
> How can I fix this ?

Start a new thread that waits for the object, and when the wait succeeds, 
post a custom message to the UI thread and handle it in a window.  This 
means breaking the code up into 2 parts, the first part before the Wait, and 
the second part after the Wait (which is moved to the message handler).  Not 
very elegant, but what can you do?

-- David


0
dc2983 (3206)
4/1/2007 2:51:28 PM
On Sun, 01 Apr 2007 15:47:01 +0200, Vincent RICHOMME
<richom.v@free.fr> wrote:

>Hi,
>
>if I have an appliaction with a window, if I call WaitForSingleObject 
>does it block the window message pump ?

Yes it does. You can put WaitForSingleObject in the message pump loop
but don't set max wait for more that few milliseconds. Have a look at
MsgWaitForMultipleObjects for another method.

-- 
Steve Wolstenholme     Neural Planner Software Ltd

EasyNN-plus. The easy way to build neural networks.

http://www.easynn.com 
0
steve (110)
4/1/2007 3:21:47 PM
"Steve Wolstenholme" <steve@tropheus.demon.co.uk> wrote in message 
news:igiv031gepmvr5jqb3iui98fn863duq89g@4ax.com...
> Yes it does. You can put WaitForSingleObject in the message pump loop
> but don't set max wait for more that few milliseconds. Have a look at
> MsgWaitForMultipleObjects for another method.
>

I try to stay away from the timeout option because if it times out, the code 
probably can't continue since the object wasn't claimed, and there may not 
be a good solution for that.  Waiting for a message to be receives works 
sometimes, but after a message is received you have to pump it with a local 
GetMessage loop, and that can cause re-entrancy.

-- David 


0
dc2983 (3206)
4/1/2007 4:32:53 PM
On Sun, 01 Apr 2007 16:32:53 GMT, "David Ching"
<dc@remove-this.dcsoft.com> wrote:

>"Steve Wolstenholme" <steve@tropheus.demon.co.uk> wrote in message 
>news:igiv031gepmvr5jqb3iui98fn863duq89g@4ax.com...
>> Yes it does. You can put WaitForSingleObject in the message pump loop
>> but don't set max wait for more that few milliseconds. Have a look at
>> MsgWaitForMultipleObjects for another method.
>>
>
>I try to stay away from the timeout option because if it times out, the code 
>probably can't continue since the object wasn't claimed, and there may not 
>be a good solution for that.  Waiting for a message to be receives works 
>sometimes, but after a message is received you have to pump it with a local 
>GetMessage loop, and that can cause re-entrancy.
>

All possible returns need to be handled but that is fairly easy. In my
code the time out returns WAIT_TIMEOUT every 100 millisecond and is
used to continue the message loop while still waiting for
WAIT_OBJECT_0. That way a timeout is not an indication of failure. A
loop count is used as a true timeout but it rarely happens before
WAIT_OBJECT_0. If it does occur the time out is handled by thread
recovery code. 

-- 
Steve Wolstenholme     Neural Planner Software Ltd

EasyNN-plus. The easy way to build neural networks.

http://www.easynn.com 
0
steve (110)
4/1/2007 5:31:55 PM
On Sun, 01 Apr 2007 14:51:28 GMT, "David Ching" <dc@remove-this.dcsoft.com>
wrote:

>"Vincent RICHOMME" <richom.v@free.fr> wrote in message 
>news:460fc34e$0$20527$426a34cc@news.free.fr...
>> How can I fix this ?
>
>Start a new thread that waits for the object, and when the wait succeeds, 
>post a custom message to the UI thread and handle it in a window.  This 
>means breaking the code up into 2 parts, the first part before the Wait, and 
>the second part after the Wait (which is moved to the message handler).  Not 
>very elegant, but what can you do?

An alternative is to write your own message loop based on
MsgWaitForMultipleObjects. For more, see Q5-Q7 here:

http://members.cox.net/doug_web/threads.htm

-- 
Doug Harrison
Visual C++ MVP
0
dsh (2498)
4/1/2007 6:01:30 PM
"Doug Harrison [MVP]" <dsh@mvps.org> wrote in message 
news:kqsv03t4gep3enm84if1p8frtvtnadruc9@4ax.com...
> An alternative is to write your own message loop based on
> MsgWaitForMultipleObjects. For more, see Q5-Q7 here:
>
> http://members.cox.net/doug_web/threads.htm
>

Thanks for the link, Doug.  Nice work!  A suggestion for you:  create a 
couple examples with projects we could download.  As it is, with all the 
caveats you mention, I'm likely to just stay with the easier way of having 
the secondary thread post a message back to a hidden window of the primary 
thread when it's done, and handling it there to complete my processing.  It 
certainly seems there is less to go wrong that way.

Thanks,
David


0
dc2983 (3206)
4/1/2007 6:44:22 PM
Yes.
				joe

On Sun, 01 Apr 2007 15:47:01 +0200, Vincent RICHOMME <richom.v@free.fr> wrote:

>Hi,
>
>if I have an appliaction with a window, if I call WaitForSingleObject 
>does it block the window message pump ?
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
4/2/2007 2:36:24 AM
Don't use WaitForSingleObject.  What are you trying to do?
					joe
On Sun, 01 Apr 2007 16:39:07 +0200, Vincent RICHOMME <richom.v@free.fr> wrote:

>David Ching a �crit :
>> "Vincent RICHOMME" <richom.v@free.fr> wrote in message 
>> news:460fb71d$0$19143$426a34cc@news.free.fr...
>>> Hi,
>>>
>>> if I have an appliaction with a window, if I call WaitForSingleObject does 
>>> it block the window message pump ?
>> 
>> Oh yes, try it:  call WaitForSingleObject() and then try dragging your 
>> window.  It will not move showing the message pump is stuck.
>> 
>> -- David 
>> 
>> 
>How can I fix this ?
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
4/2/2007 2:37:11 AM
Better still, don't use it in the main GUI thread.  It is very rare you need to do this,
but without knowing what you are trying to do, it is hard to give an alternative.
					joe

On Sun, 01 Apr 2007 16:21:47 +0100, Steve Wolstenholme <steve@tropheus.demon.co.uk> wrote:

>On Sun, 01 Apr 2007 15:47:01 +0200, Vincent RICHOMME
><richom.v@free.fr> wrote:
>
>>Hi,
>>
>>if I have an appliaction with a window, if I call WaitForSingleObject 
>>does it block the window message pump ?
>
>Yes it does. You can put WaitForSingleObject in the message pump loop
>but don't set max wait for more that few milliseconds. Have a look at
>MsgWaitForMultipleObjects for another method.
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
4/2/2007 2:38:20 AM
You are asking a generic question that requires a specific answer.

What are you waiting for, and why are you waiting for it?
					joe

On Sun, 01 Apr 2007 18:31:55 +0100, Steve Wolstenholme <steve@tropheus.demon.co.uk> wrote:

>On Sun, 01 Apr 2007 16:32:53 GMT, "David Ching"
><dc@remove-this.dcsoft.com> wrote:
>
>>"Steve Wolstenholme" <steve@tropheus.demon.co.uk> wrote in message 
>>news:igiv031gepmvr5jqb3iui98fn863duq89g@4ax.com...
>>> Yes it does. You can put WaitForSingleObject in the message pump loop
>>> but don't set max wait for more that few milliseconds. Have a look at
>>> MsgWaitForMultipleObjects for another method.
>>>
>>
>>I try to stay away from the timeout option because if it times out, the code 
>>probably can't continue since the object wasn't claimed, and there may not 
>>be a good solution for that.  Waiting for a message to be receives works 
>>sometimes, but after a message is received you have to pump it with a local 
>>GetMessage loop, and that can cause re-entrancy.
>>
>
>All possible returns need to be handled but that is fairly easy. In my
>code the time out returns WAIT_TIMEOUT every 100 millisecond and is
>used to continue the message loop while still waiting for
>WAIT_OBJECT_0. That way a timeout is not an indication of failure. A
>loop count is used as a true timeout but it rarely happens before
>WAIT_OBJECT_0. If it does occur the time out is handled by thread
>recovery code. 
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
4/2/2007 2:39:51 AM
On Sun, 01 Apr 2007 18:44:22 GMT, "David Ching" <dc@remove-this.dcsoft.com>
wrote:

>"Doug Harrison [MVP]" <dsh@mvps.org> wrote in message 
>news:kqsv03t4gep3enm84if1p8frtvtnadruc9@4ax.com...
>> An alternative is to write your own message loop based on
>> MsgWaitForMultipleObjects. For more, see Q5-Q7 here:
>>
>> http://members.cox.net/doug_web/threads.htm
>>
>
>Thanks for the link, Doug.  Nice work!  A suggestion for you:  create a 
>couple examples with projects we could download.

I should have said Q4-Q7; then it's clear that the MWFMO code in Q6 is a
replacement for the blocking WFSO call in Q4.

>As it is, with all the 
>caveats you mention, I'm likely to just stay with the easier way of having 
>the secondary thread post a message back to a hidden window of the primary 
>thread when it's done, and handling it there to complete my processing.  It 
>certainly seems there is less to go wrong that way.

If anything, there's more to understand that way. You have to know all of
Q1-Q4 and Q8 to implement it robustly, and maybe Q5-Q7 as well. :) This
reminded me, I need to update Q8 to mention that the message recipient
needs to wait on the thread to exit.

-- 
Doug Harrison
Visual C++ MVP
0
dsh (2498)
4/2/2007 8:46:07 PM
Reply:

Similar Artilces:

No data return from a sub-query causes an error message
I have a sub-query which counts the number of referrals received [Date Received]. The user then enters the criteria of the time period between [start date] and [end date] and the locality [Town]. There are 9 different localities. When the query is run and there have been no referrals in a particular locality, the table appears as column headings with no data. The query that this links into (as do several other sub-queries) then also returns no data. How can I get the first sub-query to return data for each of the different localities, with 0 if there have been no referrals? If someone ca...

Some messages are stuck in the outbox.
Some messages are stuck in the outbox. Other messages get sent ok but these oddballs just sit there. I have looked in the help section and got some reasons why this happens but I can't tell how my circumstances relate. I know this happens with some Tasks attached, but not allways. The unsent items are listed in the Outbox unitalicized. If I open them, click "Send" they stay unitalicized and do not send out when I push "Send and Receive". Have you had a look at Q195922 in the Microsoft Knowledge Base "How to troubleshoot mail stuck in the Outbox in Ou...

How to block Zip files
I just noticed that outlook is letting users accept any file as long as it is in a zip file . I want to now block Zip files. How do I do this? You can do this by installing the admpack.exe available in the Office Resource Kit. Other options might be available on your corporate firewall or virusscanner. -- Robert Sparnaaij [MVP-Outlook] www.howto-outlook.com Tips of the month: -Backup and Restore -Create an Office XP CD slipstreamed with Service Pack 3 ----- "AlanM" <nooneatall@nowhere.com> wrote in message news:eUGllA9ZEHA.1840@TK2MSFTNGP11.phx.gbl... >I just noti...

Outlook 2002
Hi, How can I stop Outlook 2002 from blocking incoming mdb files? Thanks Simon Have them send to you in a compressed format is the best way to go. If this is not possible you can unblock it as well (still not recommended); http://www.howto-outlook.com/faq/blockedattachments.htm -- Roady [MVP] www.howto-outlook.com Tips of the month: -Setting Permissions on a Mailbox -Create an Office XP CD slipstreamed with Service Pack 3 ----- "Simon" <Simon@Simon.com> wrote in message news:OPy$lDMPEHA.272@TK2MSFTNGP12.phx.gbl... > Hi, > > How can I stop Outlook 2002 from b...

Message Handling Routing
Hi, Spent best part of eight hours trying to figure this out, I'm sure its something simple Im missing. I've spent some quality time looking at POSTMESSAGE / SENDMESSAGE in my SDI MFC App. Also flicked through some articles on flounder.org, most useful. So far, I've managed to use SENDMESSAGE from my CDocument and get picked up by CMainFrame using a custom #DEFINE WMU_MYMSG and handled by OnMessage in the Messagemap. However, how could I get CDialog to hear this message? I was kinda hoping that putting my custom WMU_MSG in the CDialog Message_Map would make it work. Unfortuan...

Unknown Message Header & Pop3 Error Message
Windows Live Mail: I will start with 2 problems out of many. I get messages with unknown in the header. What could be causing this? I have messages popping up, at what I have now set at 120 seconds, that my pop3 server has not responded. How do I fix this? Why does Microsoft think they more about program interfaces than the people that actually use the programs? I am sure people like WLM but I do not. I wonder how Microsoft could be made to realize some people would like an OE6 for Windows 7. I am running Windows 7 Professional. -- <Bill> Brought to you f...

continous Error Messages
Does anyone have any ideas what this could be about Exchange 2003 I have no F:\titanium directory?? Event Type: Error Event Source: MSExchangeAL Event Category: Address List Synchronization Event ID: 8331 Date: 11/25/2003 Time: 5:13:59 AM User: N/A Computer: HOME Description: The service threw an unexpected exception which was caught at f:\titanium\dsa\src\lra\abv_dg\lservagent.cpp(4511) ...

messages disappeared...
This is a strange one. I had employee who set up outlook 2003 on his desktop recently and when he connected to the exchange server, a pop up message asked if he wanted to use the rules on the server or client. I am not sure which one he selected, however, as he was doing this, he watched about 2 months of e-mail disappear from his inbox. I am not sure if he kept outlook open or shut it down at this point. I asked him for his password and I logged into a test machine here at corp. I used uncached mode, got the same pop up message regarding the client/server rules, then watched one month of ...

Publisher Email message
When I send a message in the body of the email instead of an attachment, the spacing of the text is not the same as in the doucument I created. How can I fix this? The general wisdom here suggests that the only way to retain formatting is to attach a PDF version of your Publisher document to an email. This has the added benefit of ensuring that your recipients get your message; many people have HTML turned off for their email. Bruce "SBlank" wrote: > When I send a message in the body of the email instead of an attachment, the > spacing of the text is not...

Blocked Senders
Why is it that my questions are never answered and don't seem to appear here? I am unable to unblock senders. I have tried from the website and within Windows Live Mail all to no avail. After a short period of time they always reappear! Please help! Pretty please. Thank you. On Thu, 29 Jul 2010 10:05:30 -0700, Bruce3e <Bruce3e@discussions.microsoft.com> wrote: >Why is it that my questions are never answered Yes they are. >and don't seem to appear here? Yes, they do. Perhaps because you're using a crappy web interface? From: Bruce3e <...

Outlook error message, .pst
I have a user who when trying to delete or move messages within his .pst folder an error appears 'Message interface has returned an unknown error message'. He can view them, however cannot move or delete them. How big is the .PST file? -- Jocelyn Fiorello MVP - Outlook *** Messages sent to my e-mail address will NOT be answered -- please reply only to the newsgroup to preserve the message thread. *** In news:18eb01c3b90d$35f6b560$3101280a@phx.gbl, John Parrish wrote: > I have a user who when trying to delete or move messages > within his .pst folder an error appears &#...

Blocking Port 25
I am almost ready to put my Exchange server into production. Currently, I have a front gateway machine that receives all e-mail via port 25, does some spam and virus checking, and then forwards to the mail to my final e-mail server. I am going to keep the front gateway machine going, but switch out the backend e-mail server. I do not allow any port 25 traffic to the backend machine, except for local internal traffic. If any remote users want to send mail through our server, they connect to backend email server via port 587 and authenticate themselves. How can I do the same setup with Excha...

Recovering a message
I am fairly new to exhchange in general and am now migrating from 5.5 to 2003. I have turned on message tracking in 2003 but I don't see where we could actually recover the message itself. How do I keep copies of messages in an admin folder and then recover them when we need them. Lets assume that disk space is not a 'major' issue. Message tracking isn't what you want, then - you want journaling (a copy of all inbound/outbound mail for a particular store is directed to a mailbox). What is it you're trying to do? This is going to make your backups a lot more complicate...

how to block exe from exchange 2003
Hi i would like to know can we block exe as attachment from exchange 2003. awaiting for someone's reply regards Abhishek Dahibhate Without writing some custom code for Exchange, you will have to use a 3rd party application. Most antivirus software packages will do this. -- Jim McBee Blog: http://mostlyexchange.blogspot.com Web: http://www.somorita.com <abhishek.dahibhate@gmail.com> wrote in message news:1136856536.492574.320500@g49g2000cwa.googlegroups.com... > Hi > > i would like to know can we block exe as attachment from exchange > 2003. > > awaitin...

how to share blocked sender list
I'm currently using OL 2003 in an Exchange 2003 environment. I recently lost my inbox and I would like to get one of my colleagues extensive blocked sender's list that the junk email filter has accumulated. Is there any way on how to export this list and imported back in another mailbox. regards, -- Elvyn Gutierrez Pellerano & Herrera On Tue, 17 May 2005 06:19:01 -1000, Elvyn Gutierrez <elvyng@codetel.net.do> wrote: > I'm currently using OL 2003 in an Exchange 2003 environment. I recently > lost my inbox and I would like to get one of my colleagues exten...

Sending a message to a static control
How can I update a static control on a DialogBox from a worker thread, assuming that I have the pointer to the DialogBox in the worker thread? <peteolcott@cox.net> wrote in message news:d0df7977-db84-45ea-9ca0-ddf2003de4aa@n20g2000hsh.googlegroups.com... > How can I update a static control on a DialogBox from a worker thread, > assuming that I have the pointer to the DialogBox in the worker thread? pDialog->PostMessage(...) An example is here.. http://vcfaq.mvps.org/mfc/12.htm -- Scott McPhillips [VC++ MVP] PostMessage a user-defined message to the dialog box, and have ...

messages opening when highlighting them
Office XP; when an email arrives that has a virus, the user right-clicks the message to delete it. Immediately the message opens. Trend ScanMail is catching the viruses so that's not a problem, but why would the emails open automatically like that? Autopreview is turned off. ...

Removing duplicate messages
I have literally thousands of duplicate messages spread over dozens of folders in Oulook 2003. Is there a built-in method or third-party utility to find duplicates and delete them? Thanks! Hi! 3rd party only, e.g.: http://www.mapilab.com/outlook/duplicate_remover/ > -----Original Message----- > From: Andrew Chalk [mailto:achalk@XXXmagnacartasoftware.com] > Posted At: Monday, September 06, 2004 9:17 AM > Posted To: microsoft.public.outlook > Conversation: Removing duplicate messages > Subject: Removing duplicate messages > > I have literally thousands of duplicat...

Cannot print images in message body? (Outlook 2003)
One of my users is having a funny problem. I installed office 03 on her computer just as I've been doing since, well, 2003 I guess, and never had this problem until now. When printing Outlook messages, any images in the message body print as just a red-X at the corner of the image placement. Is there a way of toggling "print images in message body" on and off? ...

Outlook Hangs Reading Messages
I am running Windows XP Pro & Outlook 2003 via POP3 & Symantec AV I had to reinstall everything on my pc and now find when I double click an email outlook hangs for roughly a minute and then it finally opens, I have tried a data compact, reinstalling outlook and creating a new pst then importing but it still happens Does anyone have any ideas? It's driving me mad Thanks Daz Try deleting and recreating the profile as one of your steps in troubleshooting: http://www.howto-outlook.com/Faq/newprofile.htm -- K. Orland Thoughts lead on to purposes; purposes go forth in action; ...

ScanMail block extensions
Instead of making a list of extensions to block I'd rather have a list of only those extensions to allow. Is there any Anti-Virus that will do this? Thanks! Hi, you might check our Aloaha (www.aloaha.com). It does NOT have that feature yet but if you like it I am sure you will convience me to add that feature :-). To add that feature would take me onlye 1-2 days. Thanks Frank "you know who maybe" <nguser2u@spamnotAOL.com> schrieb im Newsbeitrag news:10ur9te7k4avl19@news.supernews.com... > Instead of making a list of extensions to block I'd rather have a lis...

message tracking #18
Hi, I need to be able to see who is sending excessive amounts of internal mail. I have started Message Tracking and Enable Subject logging which is now generating a nice log file. Is there an application for interpreting this data, or will I have to write something myself? many thanks, NEIL I have heard of the WebSpy Analyzer thing, but never used it myself. http://www.webspy.com/products/analyzerpremium/analyzerpremium.aspx They claim that they can analyze Exchange logs, but the software is rather pricy. I am sure you will find something better or at least cheaper for what you wan...

Error message: Style 'Percent' not found
Hi guys, I get the above error message in excel when i click on the percentage icon, any solutions to this silly problem. Thanks in advance Pantelis You're getting this because your "Percent" style has been deleted or is otherwise inaccessible. (Check Format / Style... and look for "Percent".) You can import the default styles from another workbook to correct this issue. Open the workbook with which you're having this problem (let's call it Book1 for now) and then click "New Workbook" to create a new book with the default styles intact (let...

Forward as attachment produces inline message
Hello My boss wants his secretary to forward messages to him as attachments so that he can see the original sender/recipients and do stuff like 'Reply to all'. Forwarding messages as attachments works fine internally where we all use Outlook 2000 but when he is off site he receives his messages in Outlook Express 6. (6.00.2800.1123). The problem is that in OE6, the message is displayed inline with no header information, not as an attached message. However, when I view the source of the message, I see 'Content-Dispostion: inline' so does this mean that OE is acting corr...

Blocking
I have Outlook 2000 and NEED to send and recieve messages containing a URL. However it is blocking these as an unsafe attachment. I don't care if it blocks an exe.... but my accounts program generates and email containing a URL for online payment. How can I turn off the URL blocking, help anyone??? ...