{"id":18863,"date":"2009-03-11T10:00:00","date_gmt":"2009-03-11T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2009\/03\/11\/sometimes-people-dont-even-read-what-theyre-typing\/"},"modified":"2009-03-11T10:00:00","modified_gmt":"2009-03-11T10:00:00","slug":"sometimes-people-dont-even-read-what-theyre-typing","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20090311-00\/?p=18863","title":{"rendered":"Sometimes people don&#8217;t even read what they&#8217;re typing"},"content":{"rendered":"<p><P>\nAs an even more extreme case of people\n<A HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2008\/01\/01\/6909020.aspx\">\nseeing something, confirming that they see it,\nbut not actually reading it<\/A>\nis someone who sees something,\ntypes it into an email message,\nyet still doesn&#8217;t read it.\n<\/P>\n<BLOCKQUOTE CLASS=\"q\">\n<P>\n<B>Subject<\/B>: &#8220;Invoke or BeginInvoke cannot be called\n    on a control until the window handle has been created.&#8221;\n    exception crashes our program\n<\/P>\n<P>\nI&#8217;m looking for guidance on why this exception is thrown and\nhow I can avoid it.\nHere&#8217;s a sketch of what we&#8217;re doing:\n<\/P>\n<PRE>\nvoid DoStuff() {                                                              \n  try {                \n    \/\/ attempt operation X, which throws an exception when it fails\n  } catch {                \n    this.BeginInvoke(new ShowErrorDelegate(this.OnShowError), null);\n  }\n}\n<\/PRE>\n<P>\nIf operation&nbsp;X fails, the <CODE>catch<\/CODE> clause runs,\nbut it throws the exception\n&#8220;Invoke or BeginInvoke cannot be called on a control\nuntil the window handle has been created.&#8221;\nWhy is it happening?\nIt&#8217;s crashing our program.\nRight now, we&#8217;re working around it by wrapping\nthe <CODE>BeginInvoke<\/CODE> inside its own\n<CODE>try<\/CODE>\/<CODE>catch<\/CODE>,\nbut we&#8217;d like to understand why the exception is occurring in the\nfirst place and how we can avoid it.\n<\/P>\n<\/BLOCKQUOTE>\n<P>\nNow, I don&#8217;t know much about WinForms,\nso I could be way off base here, but perhaps the problem is that\nyou&#8217;re calling\n<CODE>BeginInvoke<\/CODE> on a control before its window handle\nhas been created.\nI&#8217;m just basing that on the text that you typed\ninto the subject line and again into the message text.\nThe workaround therefore is to make sure the window handle has\nbeen created before calling <CODE>BeginInvoke<\/CODE>.\n(You can imagine any number of ways of ensuring this.)\n<\/P>\n<P>\nThough I do admire the approach of\n&#8220;We don&#8217;t know what&#8217;s going on, so we&#8217;ll just wrap it inside\nan exception handler and pretend it didn&#8217;t happen.&#8221;\n<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>As an even more extreme case of people seeing something, confirming that they see it, but not actually reading it is someone who sees something, types it into an email message, yet still doesn&#8217;t read it. Subject: &#8220;Invoke or BeginInvoke cannot be called on a control until the window handle has been created.&#8221; exception crashes [&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":[26],"class_list":["post-18863","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-other"],"acf":[],"blog_post_summary":"<p>As an even more extreme case of people seeing something, confirming that they see it, but not actually reading it is someone who sees something, types it into an email message, yet still doesn&#8217;t read it. Subject: &#8220;Invoke or BeginInvoke cannot be called on a control until the window handle has been created.&#8221; exception crashes [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/18863","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=18863"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/18863\/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=18863"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=18863"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=18863"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}