<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dave Amenta .com &#187; Delegate</title>
	<atom:link href="http://www.daveamenta.com/tag/delegate/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.daveamenta.com</link>
	<description>(dot (at dave daveamenta) com)</description>
	<lastBuildDate>Tue, 31 Jan 2012 17:22:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>C# Threading Shorthand</title>
		<link>http://www.daveamenta.com/2010-01/c-threading-shorthand/</link>
		<comments>http://www.daveamenta.com/2010-01/c-threading-shorthand/#comments</comments>
		<pubDate>Sat, 23 Jan 2010 01:20:47 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Delegate]]></category>
		<category><![CDATA[Threading]]></category>

		<guid isPermaLink="false">http://www.daveamenta.com/?p=292</guid>
		<description><![CDATA[As the complexity of an application increases, often so does the threading complication.  I have two snippets which often come in useful when dealing with threads in C#. Quickly execute code in the background: new Thread&#40;&#40;ThreadStart&#41;delegate&#40;&#41; &#123; // code here is executed on a new thread // blocking operations will not block the calling thread [...]]]></description>
			<content:encoded><![CDATA[<p>As the complexity of an application increases, often so does the threading complication.  I have two snippets which often come in useful when dealing with threads in C#.</p>
<p>Quickly execute code in the background:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">new</span> Thread<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>ThreadStart<span style="color: #008000;">&#41;</span><span style="color: #6666cc; font-weight: bold;">delegate</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// code here is executed on a new thread</span>
        <span style="color: #008080; font-style: italic;">// blocking operations will not block the calling thread</span>
    <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>Note that if this code is to be called often, a ThreadPool may be the better choice.  ThreadPools&#8217; have less overhead for instances when many threads would be created and destroyed.</p>
<p>Execute code that manipulates UI:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>Control<span style="color: #008000;">.</span><span style="color: #0000FF;">IsHandleCreated</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
   Control<span style="color: #008000;">.</span><span style="color: #0000FF;">Invoke</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>MethodInvoker<span style="color: #008000;">&#41;</span><span style="color: #6666cc; font-weight: bold;">delegate</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
   <span style="color: #008000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// code here is safe to interact with Control</span>
   <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Replace &#8216;Control&#8217; with &#8216;this&#8217; inside the Form class.  Control may refer to any control created on the UI thread.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveamenta.com/2010-01/c-threading-shorthand/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

