<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: InvokeRequired not required</title>
	<atom:link href="http://blog.lab49.com/archives/87/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.lab49.com/archives/87</link>
	<description>Technology and industry insights from Lab49.</description>
	<lastBuildDate>Sat, 24 Sep 2011 08:33:50 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Ian Griffiths</title>
		<link>http://blog.lab49.com/archives/87/comment-page-1#comment-69218</link>
		<dc:creator>Ian Griffiths</dc:creator>
		<pubDate>Mon, 02 Jul 2007 14:24:14 +0000</pubDate>
		<guid isPermaLink="false">http://daniel.lab49.com/wordpress/?p=87#comment-69218</guid>
		<description>That&#039;s so unnecessarily complex that I&#039;m just gobsmacked.

(By the way, I think I might be responsible for originating this pattern - I wrote one of the early articles on this very topic for MSDN. Hi! And although Chris Sells published something very similar earlier than that, he actually based his article on an early draft of mine... So it&#039;s my fault, if indeed there is a fault.)

Did you not realise that Control.BeginInvoke calls PostMessage for you? So you just wrote several pagefuls of code only to reproduce the behaviour you already had at the start with just a handful of code!

Encapsulating this behaviour so that you don&#039;t need to use BeginInvoke explicitly is all very well. But you don&#039;t need to re-implement it!

You started out complaining about the call to InvokeRequried, but then apparently you lost sight of that simple goal. If you want to omit the call to InvokeRequired, then just omit it. It&#039;s only in there to avoid an unnecessary post if you happen already to be on the right thread - it&#039;s essentially an optimization for a specific scenario. If you know you&#039;ll never need that, well just leave it out. And now the first example can be reduced to just a single API call, which is significantly better than what you&#039;ve written!

Of course, with .NET 2.0 and later, if you were going to build this kind of functionality, you&#039;d almost certainly wrap the SynchronizationContext instead. (That also supports WPF, even though that has a slightly different message processing model.)</description>
		<content:encoded><![CDATA[<p>That&#8217;s so unnecessarily complex that I&#8217;m just gobsmacked.</p>
<p>(By the way, I think I might be responsible for originating this pattern &#8211; I wrote one of the early articles on this very topic for MSDN. Hi! And although Chris Sells published something very similar earlier than that, he actually based his article on an early draft of mine&#8230; So it&#8217;s my fault, if indeed there is a fault.)</p>
<p>Did you not realise that Control.BeginInvoke calls PostMessage for you? So you just wrote several pagefuls of code only to reproduce the behaviour you already had at the start with just a handful of code!</p>
<p>Encapsulating this behaviour so that you don&#8217;t need to use BeginInvoke explicitly is all very well. But you don&#8217;t need to re-implement it!</p>
<p>You started out complaining about the call to InvokeRequried, but then apparently you lost sight of that simple goal. If you want to omit the call to InvokeRequired, then just omit it. It&#8217;s only in there to avoid an unnecessary post if you happen already to be on the right thread &#8211; it&#8217;s essentially an optimization for a specific scenario. If you know you&#8217;ll never need that, well just leave it out. And now the first example can be reduced to just a single API call, which is significantly better than what you&#8217;ve written!</p>
<p>Of course, with .NET 2.0 and later, if you were going to build this kind of functionality, you&#8217;d almost certainly wrap the SynchronizationContext instead. (That also supports WPF, even though that has a slightly different message processing model.)</p>
]]></content:encoded>
	</item>
</channel>
</rss>

