{"id":43473,"date":"2014-12-04T07:00:00","date_gmt":"2014-12-04T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2014\/12\/04\/if-my-wm_timer-handler-takes-longer-than-the-timer-period-will-my-queue-fill-up-with-wm_timer-messages\/"},"modified":"2014-12-04T07:00:00","modified_gmt":"2014-12-04T07:00:00","slug":"if-my-wm_timer-handler-takes-longer-than-the-timer-period-will-my-queue-fill-up-with-wm_timer-messages","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20141204-00\/?p=43473","title":{"rendered":"If my WM_TIMER handler takes longer than the timer period, will my queue fill up with WM_TIMER messages?"},"content":{"rendered":"<p>A customer was worried that they may have a problem with their message queue filling with <code>WM_TIMER<\/code> messages. &#8220;If my <code>WM_TIMER<\/code> handler takes longer than the timer period, will my queue fill up with <code>WM_TIMER<\/code> messages?&#8221;\n As we should know by now, timer messages are generated <a href=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2011\/12\/19\/10249000.aspx\"> on demand<\/a>:<\/p>\n<blockquote class=\"q\"><p> The <b>WM_TIMER<\/b> message is a low-priority message. The <b>Get&shy;Message<\/b> and <b>Peek&shy;Message<\/b> functions post this message only when  <a href=\"http:\/\/msdn.microsoft.com\/library\/windows\/desktop\/ms644902.aspx\"> no other higher-priority messages are in the thread&#8217;s message queue<\/a>. <\/p><\/blockquote>\n<p> Here&#8217;s the basic algorithm. (I&#8217;m ignoring filtering and I&#8217;m assuming that messages are removed.)<\/p>\n<ul>\n<li>Look for a posted message. If one exists, then return it. <\/li>\n<li>Was <code>Post&shy;Quit&shy;Message<\/code> called?     If so, then generate and return a <code>WM_QUIT<\/code>     message. <\/li>\n<li>Look for an input message. If one exists, then return it. <\/li>\n<li>Did the mouse move since the last call?     If so, then generate and return a <code>WM_MOUSE&shy;MOVE<\/code>     message. <\/li>\n<li>Does a window need to be repainted?     If so, then generate and return a <code>WM_PAINT<\/code>     message. <\/li>\n<li>Is there a timer that has elapsed?     If so, then generate and return a <code>WM_TIMER<\/code>     message. <\/li>\n<\/ul>\n<p> Notice that the generated messages are generated on demand by message retrieval functions. If you never call a message retrieval function, then no messages are generated. And in the case where the messages are removed (<i>i.e.<\/i>, you use <code>Get&shy;Message<\/code> or you use <code>Peek&shy;Message<\/code> with <code>PM_REMOVE<\/code>), the messages are removed immediately after being generated, so they don&#8217;t hang around very long at all.<\/p>\n<p> In particular, if your <code>WM_TIMER<\/code> handler takes longer than the timer period, and it doesn&#8217;t call a message retrieval function, then there is no opportunity for another <code>WM_TIMER<\/code> message to be generated. Only when you call a message retrieval function does there become a possibility for a <code>WM_TIMER<\/code> message to be generated. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>A customer was worried that they may have a problem with their message queue filling with WM_TIMER messages. &#8220;If my WM_TIMER handler takes longer than the timer period, will my queue fill up with WM_TIMER messages?&#8221; As we should know by now, timer messages are generated on demand: The WM_TIMER message is a low-priority message. [&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-43473","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>A customer was worried that they may have a problem with their message queue filling with WM_TIMER messages. &#8220;If my WM_TIMER handler takes longer than the timer period, will my queue fill up with WM_TIMER messages?&#8221; As we should know by now, timer messages are generated on demand: The WM_TIMER message is a low-priority message. [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/43473","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=43473"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/43473\/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=43473"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=43473"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=43473"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}