{"id":16553,"date":"2009-09-30T10:00:00","date_gmt":"2009-09-30T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2009\/09\/30\/why-do-messages-posted-by-postthreadmessage-disappear\/"},"modified":"2009-09-30T10:00:00","modified_gmt":"2009-09-30T10:00:00","slug":"why-do-messages-posted-by-postthreadmessage-disappear","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20090930-00\/?p=16553","title":{"rendered":"Why do messages posted by PostThreadMessage disappear?"},"content":{"rendered":"<p>The only thread message you can meaningfully post to a thread displaying UI is <code>WM_NULL<\/code>, and even then, it&#8217;s only because you want to wake up the message loop for some reason.\n A common problem I see is people who use <code>PostThreadMessage<\/code> to talk to a thread that is displaying UI and then wonder why the message never arrives.\n Oh, the message arrived all right. It arrived and then was thrown away.\n This is actually a repeat of an earlier entry with the title <a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2005\/04\/26\/412116.aspx\"> <i>Thread messages are eaten by modal loops<\/i><\/a>, but I&#8217;m repeating it with a better subject line to help search engines.\n But since I&#8217;m here, I may as well augment the existing article.\n Obvious places where you have modal loops on a UI thread are functions that are explicitly modal like <code>DialogBox<\/code> or <code>MessageBox<\/code> or <code>TrackPopupMenuEx(TPM_RETURNCMD)<\/code> or <code>DoDragDrop<\/code>. But there are less obvious modal loops, like the modal loop that runs <a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2006\/02\/20\/535440.aspx\"> when you click on the caption bar and hold the button<\/a> or the modal loop that runs when COM is waiting for a cross-thread call to complete.\n And since you don&#8217;t control those modal loops, when they call <code>DispatchMessage<\/code>, your thread message will simply be thrown away.<\/p>\n<p> If you need to communicate reliably with a thread that also displays UI, then create a hidden window and send or post messages to that window. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>The only thread message you can meaningfully post to a thread displaying UI is WM_NULL, and even then, it&#8217;s only because you want to wake up the message loop for some reason. A common problem I see is people who use PostThreadMessage to talk to a thread that is displaying UI and then wonder why [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-16553","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>The only thread message you can meaningfully post to a thread displaying UI is WM_NULL, and even then, it&#8217;s only because you want to wake up the message loop for some reason. A common problem I see is people who use PostThreadMessage to talk to a thread that is displaying UI and then wonder why [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/16553","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=16553"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/16553\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=16553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=16553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=16553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}