<?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: Synchronizing .NET 4 Tasks with the UI Thread</title>
	<atom:link href="http://reedcopsey.com/2009/11/17/synchronizing-net-4-tasks-with-the-ui-thread/feed/" rel="self" type="application/rss+xml" />
	<link>http://reedcopsey.com/2009/11/17/synchronizing-net-4-tasks-with-the-ui-thread/</link>
	<description>Thoughts on C#, WPF, .NET, and programming for Scientific Visualization</description>
	<lastBuildDate>Sat, 04 Sep 2010 01:57:48 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: <img src='http://reedcopsey.com/blog/wp-content/plugins/rpx/images/openid.png'/> Reed</title>
		<link>http://reedcopsey.com/2009/11/17/synchronizing-net-4-tasks-with-the-ui-thread/#comment-1121</link>
		<dc:creator><img src='http://reedcopsey.com/blog/wp-content/plugins/rpx/images/openid.png'/> Reed</dc:creator>
		<pubDate>Tue, 06 Jul 2010 17:58:18 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/?p=88#comment-1121</guid>
		<description>Tillias,

That&#039;s actually not accurate.  The default TaskScheduler, which is what is used when you do Task.Factory.StartNew, will use always use a ThreadPool thread to execute your Task, unless the LongRunning hint is specified, in which case it will use a dedicated thread (in .NET 4&#039;s implementation).  Either way, it should NEVER run on the UI thread, since the UI thread should never be on a ThreadPool thread.  

Tasks will only get scheduled on the current thread when the current thread is a threadpool thread, or the current thread is blocking on the result of a collection of Tasks (including the one that needs to execute).

That being said, if you want to force a task to run on a dedicated thread, you can do so by specifying the LongRunning hint (in the current implementation).  This is a much simpler alternative to creating a custom TaskScheduler.  Using an STA thread scheduler is really overkill, unless you specifically need an STA thread.

-Reed</description>
		<content:encoded><![CDATA[<p>Tillias,</p>
<p>That&#8217;s actually not accurate.  The default TaskScheduler, which is what is used when you do Task.Factory.StartNew, will use always use a ThreadPool thread to execute your Task, unless the LongRunning hint is specified, in which case it will use a dedicated thread (in .NET 4&#8242;s implementation).  Either way, it should NEVER run on the UI thread, since the UI thread should never be on a ThreadPool thread.  </p>
<p>Tasks will only get scheduled on the current thread when the current thread is a threadpool thread, or the current thread is blocking on the result of a collection of Tasks (including the one that needs to execute).</p>
<p>That being said, if you want to force a task to run on a dedicated thread, you can do so by specifying the LongRunning hint (in the current implementation).  This is a much simpler alternative to creating a custom TaskScheduler.  Using an STA thread scheduler is really overkill, unless you specifically need an STA thread.</p>
<p>-Reed</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tillias</title>
		<link>http://reedcopsey.com/2009/11/17/synchronizing-net-4-tasks-with-the-ui-thread/#comment-1120</link>
		<dc:creator>tillias</dc:creator>
		<pubDate>Tue, 06 Jul 2010 17:10:53 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/?p=88#comment-1120</guid>
		<description>Hi Reed! 
Task doesn&#039;t guarantee that it will be executed in separate thread. I&#039;ve faced several common scenarios where Task&#039;s delegate is executed in GUI thread and thus the application is stuck. Custom TaskScheduler must be used in order to guarantee that task will be executed in separate thread ( and not in the same GUI one).

You can reed about it here: http://tillias.wordpress.com/2010/07/05/net-4-system-threading-tasks-and-wpf-ui-thread/</description>
		<content:encoded><![CDATA[<p>Hi Reed!<br />
Task doesn&#8217;t guarantee that it will be executed in separate thread. I&#8217;ve faced several common scenarios where Task&#8217;s delegate is executed in GUI thread and thus the application is stuck. Custom TaskScheduler must be used in order to guarantee that task will be executed in separate thread ( and not in the same GUI one).</p>
<p>You can reed about it here: <a href="http://tillias.wordpress.com/2010/07/05/net-4-system-threading-tasks-and-wpf-ui-thread/" rel="nofollow">http://tillias.wordpress.com/2010/07/05/net-4-system-threading-tasks-and-wpf-ui-thread/</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>
 