<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Forms, threading, and frustration</title><link>http://blogs.msdn.com/b/ericgu/archive/2003/07/18/52390.aspx</link><description>Windows forms requires that certain operations happen on the main thread. I try to make this easier to use.</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>RE: Forms, threading, and frustration</title><link>http://blogs.msdn.com/b/ericgu/archive/2003/07/18/52390.aspx#52392</link><pubDate>Fri, 18 Jul 2003 21:44:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:52392</guid><dc:creator>Eric</dc:creator><description>Hmm. That's an interesting alternative, but it involves a fair amount of extra plumbing in all the handler functions, which I'd like to avoid. &lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=52392" width="1" height="1"&gt;</description></item><item><title>RE: Forms, threading, and frustration</title><link>http://blogs.msdn.com/b/ericgu/archive/2003/07/18/52390.aspx#52391</link><pubDate>Fri, 18 Jul 2003 10:10:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:52391</guid><dc:creator>Geert Baeyaert</dc:creator><description>You don't really need two methods. You can also use the Form.InvokeRequired property, which indicates whether or not you are on the thread the form was created on.  InvokeRequired is, for obvious reasons, thread-safe.

Your code would then look like this:
	// setup code
        object.RemoteUpdate += new UpdateHandler(RemoteUpdateFunc); 
        public void RemoteUpdateFunc(object sender, RemoteUpdateEventArgs args) 
        {
	    if (InvokeRequired) this.Invoke(new UpdateHandler(RemoteUpdateFunc), new object[] {sender, args}); 
	    else
            {
                // use the values here
            }
        }        

Using this construct, if the event is raised on a non-ui thread, the handler will first invoke itself, executing the else branch on the second pass.
In the other case, the invoke call will be skipped.

Geert&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=52391" width="1" height="1"&gt;</description></item></channel></rss>