<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7622136255348663693</id><updated>2019-01-07T01:37:53.914-08:00</updated><category term="parallel computing"/><category term="multi-threaded"/><category term="parallel extensions library"/><category term=".Net 4.0"/><category term=".net"/><category term="manycore"/><category term="work of the devil"/><category term="Source Analysis"/><category term="Visual Studio 2010"/><category term="StyleCop"/><category term="custom rule"/><category term="add-in"/><category term="tutorial"/><category term="visual studio"/><category term="debug"/><category term="patterns and practices"/><category term="software development"/><category term="style cop"/><category term="Code Camp"/><category term="book review"/><category term="coding standards"/><category term="custom rules"/><category term="microsoft"/><category term="reflector"/><category term="Composite UI Application Block"/><category term="backup"/><category term="classes"/><category term="cloud"/><category term="cloudberry"/><category term="consulting"/><category term="customer requirements"/><category term="dating"/><category term="dotnetnuke"/><category term="eharmony"/><category term="email"/><category term="estimating"/><category term="ibm"/><category term="identity theft"/><category term="internet explorer"/><category term="java"/><category term="kayaking"/><category term="kitten"/><category term="managing expectations"/><category term="media center"/><category term="movies"/><category term="online security"/><category term="online shopping"/><category term="open source"/><category term="paypal"/><category term="performance"/><category term="photography"/><category term="plugin"/><category term="s3"/><category term="technology"/><category term="television"/><category term="test-driven development"/><category term="toys"/><category term="unit testing"/><category term="user expectations"/><category term="user groups"/><category term="websphere"/><title type='text'>Love the Dot</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.lovethedot.net/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7622136255348663693/posts/default?max-results=5&amp;redirect=false'/><link rel='alternate' type='text/html' href='http://www.lovethedot.net/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/7622136255348663693/posts/default?start-index=6&amp;max-results=5&amp;redirect=false'/><author><name>Paul Jackson</name><uri>http://www.blogger.com/profile/07495739164094993738</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='22' src='http://2.bp.blogspot.com/_d6BPne4gY9w/SdfNBxLRjPI/AAAAAAAAAjc/A7lJO7kwbT0/S220/DOLPHIN1.JPG'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>45</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>5</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7622136255348663693.post-8858041015061194800</id><published>2012-07-18T19:02:00.001-07:00</published><updated>2012-07-18T19:02:10.478-07:00</updated><title type='text'>Day 20–Slip it to the right</title><content type='html'>&lt;p&gt;&lt;em&gt;&lt;strong&gt;Note: &lt;/strong&gt;Cross-posted from my &lt;a href=&quot;http://www.ontheroad2012.com/2012/07/day-20slip-it-to-right.html&quot; target=&quot;_blank&quot;&gt;roadtrip blog&lt;/a&gt; because the post has something remotely to do with scheduling.&lt;/em&gt;&lt;/p&gt;  &lt;table border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;2&quot; width=&quot;400&quot;&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign=&quot;top&quot; width=&quot;100&quot;&gt;&amp;nbsp;&lt;/td&gt;        &lt;td valign=&quot;top&quot; width=&quot;99&quot;&gt;Miles&lt;/td&gt;        &lt;td valign=&quot;top&quot; width=&quot;99&quot;&gt;MPG&lt;/td&gt;        &lt;td valign=&quot;top&quot; width=&quot;100&quot;&gt;Avg. Speed&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign=&quot;top&quot; width=&quot;100&quot;&gt;Today&lt;/td&gt;        &lt;td valign=&quot;top&quot; width=&quot;99&quot;&gt;398&lt;/td&gt;        &lt;td valign=&quot;top&quot; width=&quot;99&quot;&gt;44.1&lt;/td&gt;        &lt;td valign=&quot;top&quot; width=&quot;100&quot;&gt;59&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign=&quot;top&quot; width=&quot;100&quot;&gt;Trip&lt;/td&gt;        &lt;td valign=&quot;top&quot; width=&quot;99&quot;&gt;6129&lt;/td&gt;        &lt;td valign=&quot;top&quot; width=&quot;99&quot;&gt;46.7&lt;/td&gt;        &lt;td valign=&quot;top&quot; width=&quot;100&quot;&gt;49&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;table border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;2&quot; width=&quot;399&quot;&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign=&quot;top&quot; width=&quot;134&quot;&gt;         &lt;p&gt;Food            &lt;br /&gt;(today/budget)&lt;/p&gt;       &lt;/td&gt;        &lt;td valign=&quot;top&quot; width=&quot;133&quot;&gt;         &lt;p&gt;Hotel            &lt;br /&gt;(today/budget)&lt;/p&gt;       &lt;/td&gt;        &lt;td valign=&quot;top&quot; width=&quot;130&quot;&gt;         &lt;p&gt;Trip Savings&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign=&quot;top&quot; width=&quot;134&quot;&gt;$15 / $127&lt;/td&gt;        &lt;td valign=&quot;top&quot; width=&quot;133&quot;&gt;$100 / $100&lt;/td&gt;        &lt;td valign=&quot;top&quot; width=&quot;130&quot;&gt;AAA - $26          &lt;br /&gt;PriceLine – $945           &lt;br /&gt;Real $$ – $290&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt; &lt;a href=&quot;http://lh5.ggpht.com/-_54TTDeg87k/UAdqnUH0hMI/AAAAAAAAEm4/PXABSDeNf0c/s1600-h/image%25255B3%25255D.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;http://lh3.ggpht.com/-fRQwfZmrAjk/UAdqodjeq9I/AAAAAAAAEnA/r3O9HJgQLdA/image_thumb%25255B1%25255D.png?imgmax=800&quot; width=&quot;543&quot; height=&quot;294&quot; /&gt;&lt;/a&gt;   &lt;p&gt;Today was driving.&amp;#160; From Spokane, out of Washington, across Idaho, and then down through Montana almost to Wyoming and Yellowstone.&amp;#160; The section of Idaho we went through was all mountains, so no potato for Aryn.&lt;/p&gt;  &lt;p&gt;We did stop somewhere in Montana to get a huckleberry shake, which was quite good.&lt;/p&gt;  &lt;p&gt;The plan was for three nights here, then on across South Dakota and then up to Grand Forks, but we’re behind schedule.&lt;/p&gt;  &lt;p&gt;Much like with a software project, I had a perfectly reasonable schedule when we left Orlando.&amp;#160; I researched the driving time between cities and how long we’d stay in each place, put it in Excel, added three days for unexpected contingencies, and figured we were set.&lt;/p&gt;  &lt;p&gt;Then, early in the &lt;strike&gt;project&lt;/strike&gt; drive, scope-creep wormed its way in.&amp;#160; A night in Austin when we were supposed to push through to Carlsbad, an extra night in Albuquerque to avoid getting to Vegas on a Friday, an extra night in Vegas to see a third show – all reasonable and, hey, had that contingency time and we could probably make up a day between Vegas and San Francisco anyway.&amp;#160; &lt;/p&gt;  &lt;p&gt;Well, the convention in San Francisco made making up the day and arriving early not so feasible, which put us on track to arrive home on the 24th.&amp;#160; On schedule, but with no contingency.&lt;/p&gt;  &lt;p&gt;Then the tire problem, which ate three hours of the morning on the way out of San Francisco … three hours isn’t a problem, right?&amp;#160; But it cascaded into us coming out of Crater Lake at dusk, which doubled the time it took to get off the mountain and forced us to stop short of Seattle (cascaded in the Cascades, get it?).&amp;#160; There’s a day onto the right of the schedule.&lt;/p&gt;  &lt;p&gt;The routing off of Ranier yesterday, which took us back toward Tacoma and Seattle and around the north side of the mountain was a complete cluster.&amp;#160; I’d originally headed east out of the park, towards Yakima, which would have put us on track.&amp;#160; But on the road down to Yakima we hit construction and it was one-laned and it’s a longer road – after coming down from Sequoia in the dark and coming down from Crater lake in the dark, I didn’t want to take a chance on a third time and winding up behind schedule.&amp;#160; &lt;/p&gt;  &lt;p&gt;Look how well that worked out. &lt;/p&gt;  &lt;p&gt;So the remaining schedule looks like: &lt;/p&gt;  &lt;div align=&quot;center&quot;&gt;   &lt;table style=&quot;line-height: normal; border-collapse: collapse&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; width=&quot;210&quot; align=&quot;left&quot;&gt;&lt;colgroup&gt;&lt;col style=&quot;width: 51pt; mso-width-source: userset; mso-width-alt: 2486&quot; width=&quot;68&quot; /&gt;&lt;col style=&quot;width: 107pt; mso-width-source: userset; mso-width-alt: 5229&quot; width=&quot;143&quot; /&gt;&lt;/colgroup&gt;&lt;tbody&gt;       &lt;tr style=&quot;height: 15pt&quot; height=&quot;20&quot;&gt;         &lt;td style=&quot;padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px&quot; class=&quot;xl65&quot; height=&quot;20&quot; width=&quot;88&quot; align=&quot;right&quot;&gt;&lt;font face=&quot;Calibri&quot;&gt;&lt;font style=&quot;font-size: 11pt&quot; color=&quot;#000000&quot;&gt;7/18/2012&lt;/font&gt;&lt;/font&gt;&lt;/td&gt;          &lt;td style=&quot;padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px&quot; width=&quot;122&quot;&gt;&lt;font face=&quot;Calibri&quot;&gt;&lt;font style=&quot;font-size: 11pt&quot; color=&quot;#000000&quot;&gt;Yellowstone&lt;/font&gt;&lt;/font&gt;&lt;/td&gt;       &lt;/tr&gt;        &lt;tr style=&quot;height: 15pt&quot; height=&quot;20&quot;&gt;         &lt;td style=&quot;padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px&quot; class=&quot;xl65&quot; height=&quot;20&quot; width=&quot;88&quot; align=&quot;right&quot;&gt;&lt;font face=&quot;Calibri&quot;&gt;&lt;font style=&quot;font-size: 11pt&quot; color=&quot;#000000&quot;&gt;7/19/2012&lt;/font&gt;&lt;/font&gt;&lt;/td&gt;          &lt;td style=&quot;padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px&quot; width=&quot;122&quot;&gt;&lt;font face=&quot;Calibri&quot;&gt;&lt;font style=&quot;font-size: 11pt&quot; color=&quot;#000000&quot;&gt;Yellowstone&lt;/font&gt;&lt;/font&gt;&lt;/td&gt;       &lt;/tr&gt;        &lt;tr style=&quot;height: 15pt&quot; height=&quot;20&quot;&gt;         &lt;td style=&quot;padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px&quot; class=&quot;xl65&quot; height=&quot;20&quot; width=&quot;88&quot; align=&quot;right&quot;&gt;&lt;font face=&quot;Calibri&quot;&gt;&lt;font style=&quot;font-size: 11pt&quot; color=&quot;#000000&quot;&gt;7/20/2012&lt;/font&gt;&lt;/font&gt;&lt;/td&gt;          &lt;td style=&quot;padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px&quot; width=&quot;122&quot;&gt;&lt;font face=&quot;Calibri&quot;&gt;&lt;font style=&quot;font-size: 11pt&quot; color=&quot;#000000&quot;&gt;Black Hills&lt;/font&gt;&lt;/font&gt;&lt;/td&gt;       &lt;/tr&gt;        &lt;tr style=&quot;height: 15pt&quot; height=&quot;20&quot;&gt;         &lt;td style=&quot;padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px&quot; class=&quot;xl65&quot; height=&quot;20&quot; width=&quot;88&quot; align=&quot;right&quot;&gt;&lt;font face=&quot;Calibri&quot;&gt;&lt;font style=&quot;font-size: 11pt&quot; color=&quot;#000000&quot;&gt;7/21/2012&lt;/font&gt;&lt;/font&gt;&lt;/td&gt;          &lt;td style=&quot;padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px&quot; width=&quot;122&quot;&gt;&lt;font face=&quot;Calibri&quot;&gt;&lt;font style=&quot;font-size: 11pt&quot; color=&quot;#000000&quot;&gt;Grand Forks&lt;/font&gt;&lt;/font&gt;&lt;/td&gt;       &lt;/tr&gt;        &lt;tr style=&quot;height: 15pt&quot; height=&quot;20&quot;&gt;         &lt;td style=&quot;padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px&quot; class=&quot;xl65&quot; height=&quot;20&quot; width=&quot;88&quot; align=&quot;right&quot;&gt;&lt;font face=&quot;Calibri&quot;&gt;&lt;font style=&quot;font-size: 11pt&quot; color=&quot;#000000&quot;&gt;7/22/2012&lt;/font&gt;&lt;/font&gt;&lt;/td&gt;          &lt;td style=&quot;padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px&quot; width=&quot;122&quot;&gt;&lt;font face=&quot;Calibri&quot;&gt;&lt;font style=&quot;font-size: 11pt&quot; color=&quot;#000000&quot;&gt;Grand Forks&lt;/font&gt;&lt;/font&gt;&lt;/td&gt;       &lt;/tr&gt;        &lt;tr style=&quot;height: 15pt&quot; height=&quot;20&quot;&gt;         &lt;td style=&quot;padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px&quot; class=&quot;xl65&quot; height=&quot;20&quot; width=&quot;88&quot; align=&quot;right&quot;&gt;&lt;font face=&quot;Calibri&quot;&gt;&lt;font style=&quot;font-size: 11pt&quot; color=&quot;#000000&quot;&gt;7/23/2012&lt;/font&gt;&lt;/font&gt;&lt;/td&gt;          &lt;td style=&quot;padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px&quot; width=&quot;122&quot;&gt;&lt;font face=&quot;Calibri&quot;&gt;&lt;font style=&quot;font-size: 11pt&quot; color=&quot;#000000&quot;&gt;Grand Forks&lt;/font&gt;&lt;/font&gt;&lt;/td&gt;       &lt;/tr&gt;        &lt;tr style=&quot;height: 15pt&quot; height=&quot;20&quot;&gt;         &lt;td style=&quot;padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px&quot; class=&quot;xl65&quot; height=&quot;20&quot; width=&quot;88&quot; align=&quot;right&quot;&gt;&lt;font face=&quot;Calibri&quot;&gt;&lt;font style=&quot;font-size: 11pt&quot; color=&quot;#000000&quot;&gt;7/24/2012&lt;/font&gt;&lt;/font&gt;&lt;/td&gt;          &lt;td style=&quot;padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px&quot; width=&quot;122&quot;&gt;&lt;font face=&quot;Calibri&quot;&gt;&lt;font style=&quot;font-size: 11pt&quot; color=&quot;#000000&quot;&gt;Minneapolis&lt;/font&gt;&lt;/font&gt;&lt;/td&gt;       &lt;/tr&gt;        &lt;tr style=&quot;height: 15pt&quot; height=&quot;20&quot;&gt;         &lt;td style=&quot;padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px&quot; class=&quot;xl65&quot; height=&quot;20&quot; width=&quot;88&quot; align=&quot;right&quot;&gt;&lt;font face=&quot;Calibri&quot;&gt;&lt;font style=&quot;font-size: 11pt&quot; color=&quot;#000000&quot;&gt;7/25/2012&lt;/font&gt;&lt;/font&gt;&lt;/td&gt;          &lt;td style=&quot;padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px&quot; width=&quot;122&quot;&gt;&lt;font face=&quot;Calibri&quot;&gt;&lt;font style=&quot;font-size: 11pt&quot; color=&quot;#000000&quot;&gt;Chicago&lt;/font&gt;&lt;/font&gt;&lt;/td&gt;       &lt;/tr&gt;        &lt;tr style=&quot;height: 15pt&quot; height=&quot;20&quot;&gt;         &lt;td style=&quot;padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px&quot; class=&quot;xl65&quot; height=&quot;20&quot; width=&quot;88&quot; align=&quot;right&quot;&gt;&lt;font face=&quot;Calibri&quot;&gt;&lt;font style=&quot;font-size: 11pt&quot; color=&quot;#000000&quot;&gt;7/26/2012&lt;/font&gt;&lt;/font&gt;&lt;/td&gt;          &lt;td style=&quot;padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px&quot; width=&quot;122&quot;&gt;&lt;font face=&quot;Calibri&quot;&gt;&lt;font style=&quot;font-size: 11pt&quot; color=&quot;#000000&quot;&gt;Atlanta&lt;/font&gt;&lt;/font&gt;&lt;/td&gt;       &lt;/tr&gt;        &lt;tr style=&quot;height: 15pt&quot; height=&quot;20&quot;&gt;         &lt;td style=&quot;padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px&quot; class=&quot;xl65&quot; height=&quot;20&quot; width=&quot;88&quot; align=&quot;right&quot;&gt;&lt;font face=&quot;Calibri&quot;&gt;&lt;font style=&quot;font-size: 11pt&quot; color=&quot;#000000&quot;&gt;7/27/2012&lt;/font&gt;&lt;/font&gt;&lt;/td&gt;          &lt;td style=&quot;padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px&quot; width=&quot;122&quot;&gt;&lt;font face=&quot;Calibri&quot;&gt;&lt;font style=&quot;font-size: 11pt&quot; color=&quot;#000000&quot;&gt;Orlando&lt;/font&gt;&lt;/font&gt;&lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;I emailed work and let them know I won’t be in until Monday, 7/30.&lt;/p&gt;  </content><link rel='replies' type='application/atom+xml' href='http://www.lovethedot.net/feeds/8858041015061194800/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7622136255348663693&amp;postID=8858041015061194800' title='10 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7622136255348663693/posts/default/8858041015061194800'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7622136255348663693/posts/default/8858041015061194800'/><link rel='alternate' type='text/html' href='http://www.lovethedot.net/2012/07/day-20slip-it-to-right.html' title='Day 20–Slip it to the right'/><author><name>Paul Jackson</name><uri>http://www.blogger.com/profile/07495739164094993738</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='22' src='http://2.bp.blogspot.com/_d6BPne4gY9w/SdfNBxLRjPI/AAAAAAAAAjc/A7lJO7kwbT0/S220/DOLPHIN1.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh3.ggpht.com/-fRQwfZmrAjk/UAdqodjeq9I/AAAAAAAAEnA/r3O9HJgQLdA/s72-c/image_thumb%25255B1%25255D.png?imgmax=800" height="72" width="72"/><thr:total>10</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7622136255348663693.post-833663106052756845</id><published>2012-02-01T15:41:00.000-08:00</published><updated>2012-02-08T15:54:38.535-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="backup"/><category scheme="http://www.blogger.com/atom/ns#" term="cloud"/><category scheme="http://www.blogger.com/atom/ns#" term="cloudberry"/><category scheme="http://www.blogger.com/atom/ns#" term="s3"/><title type='text'>Consolidating My Cloud Storage–Part I: Backups</title><content type='html'>&lt;p&gt;Many years ago, when it first came out, I used &lt;a href=&quot;http://www.carbonite.com&quot; target=&quot;_blank&quot;&gt;Carbonite&lt;/a&gt; for online backups.&amp;#160; After a while, I found that I had so much NAS storage in my house that I stopped using Carbonite.&amp;#160; Then a year or so ago, I moved into an apartment and decided to go with offsite backup for my data again – in a house, you’re the only one you have to worry about burning the place down, but in an apartment you’re at the mercy of the dumbass next door – so I signed up with &lt;a href=&quot;http://www.mozy.com&quot; target=&quot;_blank&quot;&gt;Mozy&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;These are both good, cost-effective services, but over time I’ve found myself either signing up for or trying to find other uses for cloud storage.&amp;#160; Obviously services like &lt;a href=&quot;http://www.dropbox.com&quot; target=&quot;_blank&quot;&gt;Dropbox&lt;/a&gt; for file synching, but also I’d like to be able to mount cloud storage and use it directly, without using local disk space.&amp;#160; So I also looked at &lt;a href=&quot;http://www.tntdrive.com&quot; target=&quot;_blank&quot;&gt;TntDrive&lt;/a&gt;, which allows you to mount &lt;a href=&quot;http://aws.amazon.com/&quot; target=&quot;_blank&quot;&gt;Amazon S3&lt;/a&gt; buckets as a drive.&lt;/p&gt;  &lt;p&gt;At $9.99 a month for Mozy, the same for a larger Dropbox, and $39.95 for TntDrive, we’re at $270 for the first year.&amp;#160; $240 for each year after that, assuming no upgrade costs for TntDrive.&amp;#160; Mozy has a new &lt;a href=&quot;http://www.mozy.com/stash/&quot; target=&quot;_blank&quot;&gt;Stash&lt;/a&gt; service in beta, which is somewhat similar to Dropbox for the PCs attached to your Mozy account, but sometimes I need to share a large file with someone who doesn’t even have Dropbox.&amp;#160; My mom, for instance, isn’t going to install Dropbox, or delivering processed video files to customers – for that I use S3, because I can upload the file and then send my customer a download link. &lt;/p&gt;  &lt;p&gt;I had been considering a switch to &lt;a href=&quot;http://www.megaupload.com/&quot; target=&quot;_blank&quot;&gt;Megaupload&lt;/a&gt; for that, but … &lt;/p&gt;  &lt;p&gt;Anyway, I’ve always used CloudBerry’s free &lt;a href=&quot;http://www.cloudberrylab.com/free-amazon-s3-explorer-cloudfront-IAM.aspx&quot; target=&quot;_blank&quot;&gt;S3 Explorer&lt;/a&gt; for managing my S3 buckets, but I was still using a version I’d downloaded years ago and never bothered to upgrade, so I decided to see what the new version might offer.&amp;#160; Turns out that’s quite a bit, starting with a whole product for backups: &lt;a href=&quot;http://www.cloudberrylab.com/amazon-s3-microsoft-azure-google-storage-online-backup.aspx&quot; target=&quot;_blank&quot;&gt;CloudBerry S3 Backup&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;My main requirement for a backup solution is that it be as transparent and timely as Mozy or Carbonite.&amp;#160; Full system backups I can do locally to NAS periodically, the offsite solution is for data.&amp;#160; I don’t want to have to run it manually.&amp;#160; CloudBerry meets this requirement with both scheduled and &lt;a href=&quot;http://blog.cloudberrylab.com/2011/12/introducing-continues-real-time-backup.html&quot; target=&quot;_blank&quot;&gt;continuous, real-time backup&lt;/a&gt;.&amp;#160; We’ll give that a try and see how it works.&lt;/p&gt;  &lt;p&gt;After downloading the demo and installing it, the first step is to create a Backup Plan and … holy crap!&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;http://lh6.ggpht.com/-cORMkFZyU20/TzMKr7s_yEI/AAAAAAAABeY/CcvM_zNPkaQ/s1600-h/image41.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;http://lh3.ggpht.com/-PVqbRwA4PLw/TzMKsRjGTAI/AAAAAAAABeg/VCsREZJVTuA/image_thumb23.png?imgmax=800&quot; width=&quot;529&quot; height=&quot;430&quot; /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;S3, Azure, Google, and, like, a dozen other cloud storage services, including some I think they must have made up because I’ve never heard of them.&amp;#160; So, clearly, my storage target is not limited to S3 and I like that.&amp;#160; Options are good.&lt;/p&gt;  &lt;p&gt;Next we enter the connection information for the S3 account and specify a bucket:&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;http://lh6.ggpht.com/-D7vzpmpaSZk/TzMKs3S7sFI/AAAAAAAABeo/s0ptpAGmWr8/s1600-h/image42.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;http://lh3.ggpht.com/-qs_IOBBK4Iw/TzMKtVP67uI/AAAAAAAABew/AUO947nsRpI/image_thumb24.png?imgmax=800&quot; width=&quot;385&quot; height=&quot;533&quot; /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Note the little hint at the bottom of the dialog – mounting cloud storage as a &lt;a href=&quot;http://blog.cloudberrylab.com/2011/06/cloudberry-backup-introducing-virtual.html&quot; target=&quot;_blank&quot;&gt;virtual disk&lt;/a&gt; is one of the things I want to do.&amp;#160; This option is read-only, which is actually one of the uses I have for that feature.&amp;#160; I want my kids to be able to access my main music library, but not be able to change it (I don’t care what they do with their music, but I’ll take no chances with my &lt;a href=&quot;http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&amp;amp;field-keywords=katy+perry&amp;amp;tag=montalia&quot; target=&quot;_blank&quot;&gt;Katy Perry&lt;/a&gt; MP3s).&amp;#160; We’ll check that feature out in a later post.&lt;/p&gt;  &lt;p&gt;Next we specify a new S3 bucket to contain the backup and select its location.&amp;#160; This is one of the things that I like about an S3 solution – this degree of control may not be for everyone, but, well, I have control-issues, so this makes me happy.&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;http://lh3.ggpht.com/-payoL38kDX0/TzMKthtt40I/AAAAAAAABe4/wWLlzTjz7lI/s1600-h/image12.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;http://lh3.ggpht.com/-Rqfj1g9oCbg/TzMKuHHXN-I/AAAAAAAABfA/-tQucjc7sSc/image_thumb6.png?imgmax=800&quot; width=&quot;387&quot; height=&quot;271&quot; /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Um … did I mention lots of control?&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;http://lh4.ggpht.com/-6moJ_nS1cl4/TzMKuRWD5BI/AAAAAAAABfI/W9oSWuFEN9c/s1600-h/image18.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;http://lh6.ggpht.com/--mhhkFg6_EI/TzMKuzPb3CI/AAAAAAAABfQ/8f_EyNkmxoA/image_thumb10.png?imgmax=800&quot; width=&quot;590&quot; height=&quot;484&quot; /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;I went with Advanced Mode to support multiple versions of the files and block level backups (backing up only the changed segments of files).&amp;#160; I also turned on the Volume Shadow Copy Service, as I want this backing up changes continuously while I use the computer.&lt;/p&gt;  &lt;p&gt;Then we select the files and directories we want to backup:&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;http://lh6.ggpht.com/-SPokQrul5Q8/TzMKvfZJRfI/AAAAAAAABfY/5RxQxckgCnA/s1600-h/image231.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;http://lh5.ggpht.com/--69o2s7OeUY/TzMKwF9R_BI/AAAAAAAABfg/d_w4W_yhDGw/image_thumb13.png?imgmax=800&quot; width=&quot;549&quot; height=&quot;445&quot; /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;A nice feature here is the ability to add a network share to your backup, something not found in services like Mozy or Carbonite (last I checked).&lt;/p&gt;  &lt;p&gt;But something those services do offer that CloudBerry doesn’t seem to is Explorer-integration:&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;http://lh6.ggpht.com/-GcVk9vCDX7M/TzMKwTR5H0I/AAAAAAAABfo/jOw1UGpZsuk/s1600-h/image30.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;http://lh4.ggpht.com/-xh6kWCt0J2s/TzMKxBeo5KI/AAAAAAAABfw/Lz8A6oZ8Bnw/image_thumb16.png?imgmax=800&quot; width=&quot;474&quot; height=&quot;304&quot; /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;It would be nice to be able to add a file or folder to a backup plan from Explorer – because opening the CloudBerry app and changing it there is too much work and I’m lazy.&amp;#160; It’d be a bit more work to do than Mozy’s, because Mozy only has one backup plan.&amp;#160; I’d suggest an “Add to CloudBerry Backup &amp;gt;” menu with submenus for applicable plans.&amp;#160; &lt;/p&gt;  &lt;p&gt;More options:&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;http://lh3.ggpht.com/-12g3iRHANnk/TzMKxq4dCqI/AAAAAAAABf4/cAvGlGv8JEs/s1600-h/image35.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;http://lh4.ggpht.com/-88TQup-IvE4/TzMKyIws3OI/AAAAAAAABgA/K9O6W89cWmc/image_thumb19.png?imgmax=800&quot; width=&quot;487&quot; height=&quot;398&quot; /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;And another suggestion: I’d like to be able to specify filters like these per folder/subfolder.&amp;#160; For instance, I might have a folder for downloaded apps that I want to keep the installs for (exe, msi, etc.), but I’d like to ignore the exes and dlls in my Visual Studio projects.&amp;#160; That would be interesting … because it would satisfy my control issues …&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;http://lh6.ggpht.com/-3m3yg1tSCJc/TzMKzF8mk6I/AAAAAAAABgQ/7QMRiazysxQ/s1600-h/image40.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;http://lh4.ggpht.com/-oReYGcgfMpI/TzMK0Gw8MyI/AAAAAAAABgY/VTNdCZKdmdU/image_thumb22.png?imgmax=800&quot; width=&quot;496&quot; height=&quot;399&quot; /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Compression and encryption are self-explanatory, but &lt;a href=&quot;http://aws.amazon.com/about-aws/whats-new/2010/05/19/announcing-amazon-s3-reduced-redundancy-storage/&quot; target=&quot;_blank&quot;&gt;Reduced Redundancy Storage&lt;/a&gt; requires some explanation.&amp;#160; According to Amazon, S3 offers 99.999999999% durability and can survive concurrent data loss in two facilities – in layman’s terms that means “really, really good”.&amp;#160; RRS “only” offers 99.99% durability and data loss in a single facility.&amp;#160; &lt;a href=&quot;http://stackoverflow.com/questions/4179027/99-99-durability-what-does-it-mean&quot; target=&quot;_blank&quot;&gt;What does that mean?&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Lots of options for cleaning up old versions of files and deleted files:&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;http://lh5.ggpht.com/-HvPEo6IIpZI/TzMK0ltnUYI/AAAAAAAABgg/tRvMYoqXgKc/s1600-h/image47.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;http://lh5.ggpht.com/-etG31h2GWQk/TzMK1wVe7mI/AAAAAAAABgo/_bbAYqvFDWk/image_thumb27.png?imgmax=800&quot; width=&quot;507&quot; height=&quot;408&quot; /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;And here’s where I can make the setting that will let me replace Mozy:&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;http://lh4.ggpht.com/-wZ9TqbQMTnA/TzMK2OUEZmI/AAAAAAAABgw/ltEv_-IwuU4/s1600-h/image52.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;http://lh3.ggpht.com/-V-4w0SzqpXE/TzMK2hzllxI/AAAAAAAABg4/HBsTbofxYgw/image_thumb30.png?imgmax=800&quot; width=&quot;513&quot; height=&quot;415&quot; /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Real-time Backup is what I’m looking for myself, but the product’s flexible and powerful enough to handle a variety of backup strategies.&amp;#160; Why real-time?&amp;#160; Well, this is what my Mozy status looks like today:&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;http://lh4.ggpht.com/-krYl3pzGxUw/TzMK3DzkA_I/AAAAAAAABhA/2amMFYbZudE/s1600-h/image8.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;http://lh4.ggpht.com/-jtDVJlwaPPI/TzMK3uWu-EI/AAAAAAAABhI/r5gqp1tab28/image_thumb3.png?imgmax=800&quot; width=&quot;473&quot; height=&quot;285&quot; /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;I have it scheduled for twice a day and the laptop was on most of last night and all day the day before … but it hasn’t backed up in two days, despite my twice a day schedule.&amp;#160; I like the idea of the backup application being notified of changes and backing up right then, with possibly a scheduled backup to, well, backup the backup.&lt;/p&gt;  &lt;p&gt;And finally email notifications for the backup status:&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;http://lh6.ggpht.com/-HamWw9Q6RFI/TzMK478rJaI/AAAAAAAABhQ/L8Y8BYWzOgQ/s1600-h/image57.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;http://lh3.ggpht.com/-S8--Hgfo6Yg/TzMK5enKx6I/AAAAAAAABhY/1qyrdVIF1y8/image_thumb33.png?imgmax=800&quot; width=&quot;516&quot; height=&quot;418&quot; /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;And the configuration’s done so I ran the backup.&amp;#160; My dataset for this was about 14GB, which brings us to some areas in which CloudBerry Backup could be improved.&amp;#160; There doesn’t seem to be a way to determine the original and compressed total for a given backup plan.&amp;#160; This is information that I’d like to know, so I had to figure out the original size manually by reviewing the folders I’d selected for backup:&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;http://lh4.ggpht.com/-MU4T2FCNEgU/TzMK5__tQOI/AAAAAAAABhk/Kqk0NlqW7Bo/s1600-h/image131.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;http://lh4.ggpht.com/-rBPVzlO2J08/TzMK6qJy6SI/AAAAAAAABhw/sTptgj1pQAE/image_thumb61.png?imgmax=800&quot; width=&quot;524&quot; height=&quot;424&quot; /&gt;&lt;/a&gt;&amp;#160; &lt;/p&gt;  &lt;p&gt;Improvement Opportunity: In the review of the selected folders, the UI for a partial folder is very faint and indistinguishable from an unselected folder.&amp;#160; Compare this with Mozy’s view:&lt;/p&gt;  &lt;p align=&quot;center&quot;&gt;   &lt;table border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;2&quot; width=&quot;300&quot;&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign=&quot;top&quot; width=&quot;150&quot;&gt;&lt;a href=&quot;http://lh6.ggpht.com/-hNQ3YxlM7k0/TzMK7dYRrDI/AAAAAAAABh4/C-SWFBbIzZ8/s1600-h/image16.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;http://lh6.ggpht.com/-yppFJYI78ys/TzMK7r3kdQI/AAAAAAAABiA/3GbJSWQLpZY/image_thumb7.png?imgmax=800&quot; width=&quot;103&quot; height=&quot;27&quot; /&gt;&lt;/a&gt;&lt;/td&gt;          &lt;td valign=&quot;top&quot; width=&quot;150&quot;&gt;&lt;a href=&quot;http://lh4.ggpht.com/-gMkqyQP2ecU/TzMK75o5yQI/AAAAAAAABiI/EKXCD0QugRY/s1600-h/image19.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;http://lh5.ggpht.com/-PgGvhUKAVEU/TzMK8F3ROCI/AAAAAAAABiQ/LnHG5ehBFiA/image_thumb8.png?imgmax=800&quot; width=&quot;105&quot; height=&quot;24&quot; /&gt;&lt;/a&gt;&lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign=&quot;top&quot; width=&quot;150&quot;&gt;CloudBerry&lt;/td&gt;          &lt;td valign=&quot;top&quot; width=&quot;150&quot;&gt;Mozy&lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;  &lt;p&gt;The Mozy representation is far more usable.&lt;/p&gt;  &lt;p&gt;I used &lt;a href=&quot;http://www.bucketexplorer.com/&quot; target=&quot;_blank&quot;&gt;S3 Bucket Explorer&lt;/a&gt; to determine the size of the files on S3 and came up with a little less than 12GB after compression.&amp;#160; CloudBerry’s S3 Explorer also has the capability to determine bucket size, and in a much nicer interface that allows you to drill down and graphically see the space used by different folders:&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;http://lh5.ggpht.com/-6VeXsmMRNC0/TzMK8QvU0oI/AAAAAAAABiY/YCgjomklRbk/s1600-h/image23.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;http://lh4.ggpht.com/-9QtQh19DQDs/TzMK9PfE8TI/AAAAAAAABig/6mAgzjCML7w/image_thumb101.png?imgmax=800&quot; width=&quot;533&quot; height=&quot;297&quot; /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Unfortunately for me, the free version is limited to 2GB of objects for this report.&amp;#160; &lt;/p&gt;  &lt;p&gt;Improvement Opportunity: I’d like to see this same capability in the backup tool – for a given Backup Plan I’d like to see, in the same graphical drill-down, the original size on disk and the compressed size on S3.&lt;/p&gt;  &lt;p&gt;My next test was of the “continuous” feature, so I created a new folder in my documents library and dropped a Word document in it, using S3 Explorer to watch the bucket.&amp;#160; Within about two minutes, the new folder and Word document showed up on S3.&amp;#160; This is a feature Mozy doesn’t offer – it may not be something I use for all folders, but CloudBerry offers the flexibility to have multiple backup plans, scheduled, continuous, or on-demand, so I can set the appropriate plan for each type of data.&lt;/p&gt;  &lt;p&gt;Next I wanted to test performance, so I created a new folder with three 700MB files.&amp;#160; I then added these to a CloudBerry backup plan and to Mozy in order to compare the upload speed of each.&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;http://lh5.ggpht.com/-xbzSGRrUsQA/TzMK-tUfmbI/AAAAAAAABio/ur-4elkIPSM/s1600-h/image28.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;http://lh3.ggpht.com/-fhTEwMQNBn4/TzMK_DYXR_I/AAAAAAAABiw/Ko8v1JjZ6kI/image_thumb131.png?imgmax=800&quot; width=&quot;590&quot; height=&quot;213&quot; /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;http://lh6.ggpht.com/-rGQCdfHrS60/TzMK_eV5lsI/AAAAAAAABi4/rMEGW__scXk/s1600-h/image4.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;http://lh4.ggpht.com/-CkPoFUClNZg/TzMK_lCKqfI/AAAAAAAABjA/wSRgPcqlNfk/image_thumb1.png?imgmax=800&quot; width=&quot;451&quot; height=&quot;270&quot; /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Ouch … what’s up with this?&amp;#160; CloudBerry averages about 500KB/second when it’s backing up files, but Mozy averages 3.5-4MB/second.&amp;#160; That’s a pretty significant difference (a 7x to 8x difference in performance).&amp;#160; &lt;/p&gt;  &lt;p&gt;CloudBerry, of course, is dependent on the S3 infrastructure, so this can probably be blamed on Amazon.&amp;#160; This difference doesn’t thrill me, but I’m more concerned with the restore (download) performance.&amp;#160; After all, the backup will be in the background and transparent, but when it comes time to restore it’ll be because a Bad Thing has happened and I want access to my data.&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;http://lh4.ggpht.com/-PwMj3kgvSls/TzMK_869K4I/AAAAAAAABjI/YoTocMF0PVg/s1600-h/image9%25255B1%25255D.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;http://lh3.ggpht.com/-JC4P_bS5R60/TzMLAVB-4LI/AAAAAAAABjQ/SG7cQ5KefrU/image_thumb4.png?imgmax=800&quot; width=&quot;460&quot; height=&quot;276&quot; /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;http://lh3.ggpht.com/-9KwDiruG0fk/TzMLA8J4hhI/AAAAAAAABjY/lU2Lt3c4_iM/s1600-h/image14%25255B1%25255D.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;http://lh3.ggpht.com/-mIVuKfTArDY/TzMLBf2aYvI/AAAAAAAABjk/sNBft736AlU/image_thumb7%25255B1%25255D.png?imgmax=800&quot; width=&quot;563&quot; height=&quot;456&quot; /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;It seems Mozy still has the edge here, but the 4.2MB/second restore speed is completely respectable. &lt;/p&gt;  &lt;p&gt;So I’ll run this for about a week and then see where we are.&lt;/p&gt;  </content><link rel='replies' type='application/atom+xml' href='http://www.lovethedot.net/feeds/833663106052756845/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7622136255348663693&amp;postID=833663106052756845' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7622136255348663693/posts/default/833663106052756845'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7622136255348663693/posts/default/833663106052756845'/><link rel='alternate' type='text/html' href='http://www.lovethedot.net/2012/02/consolidating-my-cloud-storagepart-i.html' title='Consolidating My Cloud Storage–Part I: Backups'/><author><name>Paul Jackson</name><uri>http://www.blogger.com/profile/07495739164094993738</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='22' src='http://2.bp.blogspot.com/_d6BPne4gY9w/SdfNBxLRjPI/AAAAAAAAAjc/A7lJO7kwbT0/S220/DOLPHIN1.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh3.ggpht.com/-PVqbRwA4PLw/TzMKsRjGTAI/AAAAAAAABeg/VCsREZJVTuA/s72-c/image_thumb23.png?imgmax=800" height="72" width="72"/><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7622136255348663693.post-3706047076505006025</id><published>2010-06-03T17:31:00.001-07:00</published><updated>2010-06-03T17:31:39.447-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term=".net"/><category scheme="http://www.blogger.com/atom/ns#" term=".Net 4.0"/><category scheme="http://www.blogger.com/atom/ns#" term="manycore"/><category scheme="http://www.blogger.com/atom/ns#" term="multi-threaded"/><category scheme="http://www.blogger.com/atom/ns#" term="parallel computing"/><category scheme="http://www.blogger.com/atom/ns#" term="Visual Studio 2010"/><category scheme="http://www.blogger.com/atom/ns#" term="work of the devil"/><title type='text'>Parallel Programming in .Net 4.0 and VS2010: Part II – WinForms, Tasks and Service Level Agreements</title><content type='html'>&lt;p&gt;&lt;em&gt;Note: This article was &lt;a href=&quot;http://www.lovethedot.net/2009/01/parallel-programming-in-net-40-and_30.html&quot; target=&quot;_blank&quot;&gt;originally published&lt;/a&gt; with code samples from the Visual Studio 2010 Beta.&amp;#160; This version has been updated for the release version.&amp;#160; This article, especially, has changed due to the changes in the Task cancellation mechanism.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;The Console application in my &lt;a href=&quot;http://www.lovethedot.net/2010/02/parallel-programming-in-net-40-and.html&quot;&gt;previous post&lt;/a&gt; was actually the prototype for a more robust WinForms implementation – I have a customer who likes prime numbers.&amp;#160; We’ll call him Bob.&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;http://lh3.ggpht.com/_d6BPne4gY9w/TAhJY0fPMZI/AAAAAAAABMA/CWzgW33_aWQ/s1600-h/image%5B3%5D.png&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;http://lh3.ggpht.com/_d6BPne4gY9w/TAhJZBFSe5I/AAAAAAAABME/ovoQoXPwDZI/image_thumb%5B1%5D.png?imgmax=800&quot; width=&quot;326&quot; height=&quot;326&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Sure, Bob’s a little weird, but he typically pays his invoices Net-10, so I like to keep him happy.&lt;/p&gt;  &lt;p&gt;I first deployed the application to Bob without using the Parallel Task Library, so it was single-threaded:&lt;/p&gt;  &lt;div style=&quot;border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px&quot;&gt;   &lt;div style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;     &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;void&lt;/span&gt; goButton_Click(&lt;span style=&quot;color: #0000ff&quot;&gt;object&lt;/span&gt; sender, EventArgs e)&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;  {&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;      Stopwatch watch = Stopwatch.StartNew();&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;      &lt;span style=&quot;color: #0000ff&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #0000ff&quot;&gt;int&lt;/span&gt; i = 0; i &amp;lt; 100; i++)&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;      {&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;          doWork(i);&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;      }&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;      watch.Stop();&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;      listBox1.Items.Add(String.Format(&lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;Entire process took {0} milliseconds&amp;quot;&lt;/span&gt;, watch.ElapsedMilliseconds));&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;  }&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;  &lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;  &lt;span style=&quot;color: #0000ff&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;void&lt;/span&gt; doWork(&lt;span style=&quot;color: #0000ff&quot;&gt;int&lt;/span&gt; instance)&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;  {&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;      Stopwatch watch = Stopwatch.StartNew();&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;      &lt;span style=&quot;color: #0000ff&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #0000ff&quot;&gt;int&lt;/span&gt; i = 3; i &amp;lt; 30000; i++) &lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;      {&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;          &lt;span style=&quot;color: #0000ff&quot;&gt;if&lt;/span&gt; (isPrime(i));     &lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;      } &lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;      watch.Stop();&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;      listBox1.Items.Add(String.Format(&lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;{0} took {1} milliseconds&amp;quot;&lt;/span&gt;, instance, watch.ElapsedMilliseconds));&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;  }&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;  &lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;  &lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;  &lt;span style=&quot;color: #0000ff&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;bool&lt;/span&gt; isPrime(&lt;span style=&quot;color: #0000ff&quot;&gt;int&lt;/span&gt; i)&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;  {&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;      &lt;span style=&quot;color: #0000ff&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #0000ff&quot;&gt;int&lt;/span&gt; j = 2; j &amp;lt;= (i / 2); j++) &lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;      { &lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;          &lt;span style=&quot;color: #0000ff&quot;&gt;if&lt;/span&gt; ((i % j) == 0)             &lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;              &lt;span style=&quot;color: #0000ff&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;false&lt;/span&gt;; &lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;      } &lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;      &lt;span style=&quot;color: #0000ff&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;true&lt;/span&gt;; &lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;  }&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Bob was happy with the results, but not with the performance:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;“Sixteen seconds is too long!&amp;#160; I can’t wait that long!&amp;#160; Time is money in my business!&amp;#160; It needs to be instantaneous!”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I tried to explain to Bob that “instantaneous” is not a Service-Level Agreement, but he was adamant: “Faster!”&lt;/p&gt;

&lt;p&gt;And, no, I have no idea what Bob’s business is or why he needs this application.&amp;#160; He pays on time – I don’t ask a lot of questions.&lt;/p&gt;

&lt;p&gt;So my first change is to make the &lt;em&gt;for-&lt;/em&gt;loop parallel:&lt;/p&gt;

&lt;div style=&quot;border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px&quot;&gt;
  &lt;div style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;
    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;Parallel.For(0, 100, i =&amp;gt;&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt; {&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;     doWork(i);&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt; });&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Unfortunately, changing an application from single- to multi-threaded can have unintended consequences.&amp;#160; When writing a single-threaded WinForms application you don’t have to worry about things like WinForms Controls only being accessible from the UI thread:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://lh6.ggpht.com/_d6BPne4gY9w/TAhJZmsL51I/AAAAAAAABMI/6JK_W_3wU_Q/s1600-h/image%5B8%5D.png&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;http://lh4.ggpht.com/_d6BPne4gY9w/TAhJZ3l8GzI/AAAAAAAABMM/vtCnxobL8uc/image_thumb%5B4%5D.png?imgmax=800&quot; width=&quot;729&quot; height=&quot;293&quot; /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The doWork() method accesses the ListBox directly to add items to it, but since doWork() is now being run on a different thread, it violates a fundamental Windows requirement that UI controls only be accessed from the thread they were created on.&lt;/p&gt;

&lt;p&gt;This problem isn’t new with .Net 4.0, it’s always been there and remains even in WPF.&amp;#160; UI Controls can only be accessed from the thread that created them and that should be the main application thread.&amp;#160; So there are some hoops we have to jump through in order to get back to the UI thread in order to update the control.&amp;#160; There are a &lt;a href=&quot;http://www.google.com/search?hl=en&amp;amp;q=.net+winforms+ui+thread+invoke&amp;amp;aq=f&amp;amp;oq=&quot;&gt;number of articles&lt;/a&gt; available that describe patterns for dealing with this – the one I typically use (now) is:&lt;/p&gt;

&lt;div style=&quot;border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px&quot;&gt;
  &lt;div style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;
    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;void&lt;/span&gt; updateList(&lt;span style=&quot;color: #0000ff&quot;&gt;string&lt;/span&gt; item)&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;{&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;    &lt;span style=&quot;color: #0000ff&quot;&gt;if&lt;/span&gt; (listBox1.InvokeRequired)&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;        listBox1.BeginInvoke((Action)&lt;span style=&quot;color: #0000ff&quot;&gt;delegate&lt;/span&gt;() { listBox1.Items.Add(item); });&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;    &lt;span style=&quot;color: #0000ff&quot;&gt;else&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;        listBox1.Items.Add(item);&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;}&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Then I change the doWork() method to add items to the list through the addToList() method instead of directly:&lt;/p&gt;

&lt;div style=&quot;border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px&quot;&gt;
  &lt;div style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;
    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;void&lt;/span&gt; doWork(&lt;span style=&quot;color: #0000ff&quot;&gt;int&lt;/span&gt; instance)&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt; {&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;     Stopwatch watch = Stopwatch.StartNew();&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;     &lt;span style=&quot;color: #0000ff&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #0000ff&quot;&gt;int&lt;/span&gt; i = 3; i &amp;lt; 30000; i++) &lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;     {&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;         &lt;span style=&quot;color: #0000ff&quot;&gt;if&lt;/span&gt; (isPrime(i));     &lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;     } &lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;     watch.Stop();&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;     updateList(String.Format(&lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;{0} took {1} milliseconds&amp;quot;&lt;/span&gt;, instance, watch.ElapsedMilliseconds));&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&amp;#160;&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt; }&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;And, for consistency, I do the same to the goButton_Click where the total elapsed time is recorded.&lt;/p&gt;

&lt;p&gt;Running the application now results in the same performance improvement seen in the &lt;a href=&quot;http://www.lovethedot.net/2010/02/parallel-programming-in-net-40-and.html&quot;&gt;console application&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://lh4.ggpht.com/_d6BPne4gY9w/TAhJaRQWtuI/AAAAAAAABMQ/p7SLn3gkggY/s1600-h/image%5B12%5D.png&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;http://lh4.ggpht.com/_d6BPne4gY9w/TAhJakjVIKI/AAAAAAAABMU/zlESA-yU7MA/image_thumb%5B6%5D.png?imgmax=800&quot; width=&quot;320&quot; height=&quot;327&quot; /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;I take this new version to Bob, pretty confident that dropping the processing time from almost 16 seconds to 4 will make him happy.&amp;#160; The only problem is that I’m not sure how to bill him for it – after all, using the Parallel Extensions I was able to get this speed improvement with only a few minutes of work -- .Net 4.0 might improve my productivity, but it could have a negative effect on my Accounts Receivable.&lt;/p&gt;

&lt;p&gt;Unfortunately, Bob’s not as impressed as I thought he’d be:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;“4 seconds?&amp;#160; I still have to wait 4 seconds?&amp;#160; Faster! Faster! Faster!&amp;#160; I need instantaneous results!&amp;#160; I need to start working with the list as soon as I click the Go button!”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Bob’s a little high-strung.&lt;/p&gt;

&lt;p&gt;But something he said sparks an idea.&amp;#160; Bob needs to work with the list immediately, but not with the &lt;em&gt;entire&lt;/em&gt; list.&amp;#160; His process is to do something with each item in the list (no, I still don’t know what he does with them), so he doesn’t need everything, he just needs enough to start working.&amp;#160; While he’s working on the early results, later results can be completed and returned.&lt;/p&gt;

&lt;p&gt;The way we’d do that today is to start our own background thread using something like ThreadPool.QueueUserWorkItem().&amp;#160; I can move the current code from button click event to another method, then use QueueUserWorkItem to run that code on a background thread:&lt;/p&gt;

&lt;div style=&quot;border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px&quot;&gt;
  &lt;div style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;
    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;void&lt;/span&gt; goButton_Click(&lt;span style=&quot;color: #0000ff&quot;&gt;object&lt;/span&gt; sender, EventArgs e)&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;{&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;    ThreadPool.QueueUserWorkItem(&lt;span style=&quot;color: #0000ff&quot;&gt;new&lt;/span&gt; WaitCallback(freeUi));&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;}&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&amp;#160;&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;void&lt;/span&gt; freeUi(&lt;span style=&quot;color: #0000ff&quot;&gt;object&lt;/span&gt; sync)&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;{&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;    Stopwatch watch = Stopwatch.StartNew();&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;    &lt;span style=&quot;color: #008000&quot;&gt;//for (int i = 0; i &amp;lt; 100; i++)&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;    Parallel.For(0, 100, i =&amp;gt;&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;    {&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;        doWork(i);&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;    });&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;    watch.Stop();&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;    updateList(String.Format(&lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;Entire process took {0} milliseconds&amp;quot;&lt;/span&gt;, watch.ElapsedMilliseconds));&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;}&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;This works great.&amp;#160; The list starts populating immediately and Bob will be able to get started working on the first items in the list while the remaining work finishes.&amp;#160; But QueueUserWorkItem is a little passé – it’s very … .Net 2.0 – what does 4.0 offer us to replace it with?&lt;/p&gt;

&lt;p&gt;Enter the System.Threading.Tasks namespace and the Task class.&amp;#160; Using the StartNew() method on Task.Factory, we can create our background thread using the new, .Net 4.0 Task model, rather than via the old ThreadPool.&amp;#160; New is better.&amp;#160; Mostly.&amp;#160; Except &lt;a href=&quot;http://en.wikipedia.org/wiki/New_Coke&quot;&gt;New Coke&lt;/a&gt; – New Coke was bad.&amp;#160; Very, very bad.&lt;/p&gt;

&lt;div style=&quot;border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px&quot;&gt;
  &lt;div style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;
    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #606060&quot;&gt;   1:&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;void&lt;/span&gt; goButton_Click(&lt;span style=&quot;color: #0000ff&quot;&gt;object&lt;/span&gt; sender, EventArgs e)&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #606060&quot;&gt;   2:&lt;/span&gt;  {&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #606060&quot;&gt;   3:&lt;/span&gt;      Task.Factory.StartNew(() =&amp;gt; { freeUi(&lt;span style=&quot;color: #0000ff&quot;&gt;null&lt;/span&gt;); });&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #606060&quot;&gt;   4:&lt;/span&gt;  }&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Bob is thrilled with this new version.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;“I’m thrilled!&amp;#160; This is great!&amp;#160; It’s instantaneous! By the way … how do I make it stop?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So Bob wants a way to stop the population of the list once he’s started it.&amp;#160; We can give him that with the CancellationTokenSource and CancellationToken.&amp;#160; First we need a token to use for cancelation:&lt;/p&gt;

&lt;div style=&quot;border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px&quot;&gt;
  &lt;div style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;
    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #606060&quot;&gt;   1:&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;private&lt;/span&gt; CancellationTokenSource tokenSource;&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #606060&quot;&gt;   2:&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;private&lt;/span&gt; CancellationToken token;&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #606060&quot;&gt;   3:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #606060&quot;&gt;   4:&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;public&lt;/span&gt; Form1()&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #606060&quot;&gt;   5:&lt;/span&gt; {&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #606060&quot;&gt;   6:&lt;/span&gt;     InitializeComponent();&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #606060&quot;&gt;   7:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #606060&quot;&gt;   8:&lt;/span&gt;     tokenSource = &lt;span style=&quot;color: #0000ff&quot;&gt;new&lt;/span&gt; CancellationTokenSource();&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #606060&quot;&gt;   9:&lt;/span&gt;     token = tokenSource.Token;&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #606060&quot;&gt;  10:&lt;/span&gt; }&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Now this token must be passed to the Task:&lt;/p&gt;

&lt;div style=&quot;border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px&quot;&gt;
  &lt;div style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;
    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #606060&quot;&gt;   1:&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;void&lt;/span&gt; goButton_Click(&lt;span style=&quot;color: #0000ff&quot;&gt;object&lt;/span&gt; sender, EventArgs e)&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #606060&quot;&gt;   2:&lt;/span&gt; {&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #606060&quot;&gt;   3:&lt;/span&gt;     var task = Task.Factory.StartNew(() =&amp;gt; { freeUi(&lt;span style=&quot;color: #0000ff&quot;&gt;null&lt;/span&gt;); }, token);&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #606060&quot;&gt;   4:&lt;/span&gt; }&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;And, via a ParallelOptions object, to the Parallel.For loop:&lt;/p&gt;

&lt;div style=&quot;border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px&quot;&gt;
  &lt;div style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;
    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #606060&quot;&gt;   1:&lt;/span&gt; var options = &lt;span style=&quot;color: #0000ff&quot;&gt;new&lt;/span&gt; ParallelOptions();&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #606060&quot;&gt;   2:&lt;/span&gt; options.CancellationToken = token;&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #606060&quot;&gt;   3:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #606060&quot;&gt;   4:&lt;/span&gt; Parallel.For(0, 100, options, i =&amp;gt;&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #606060&quot;&gt;   5:&lt;/span&gt; {&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #606060&quot;&gt;   6:&lt;/span&gt;     doWork(i);&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #606060&quot;&gt;   7:&lt;/span&gt; });&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;And, finally, having given Bob a Cancel button, we would call Cancel() on the CancellationTokenSource when he clicks it:&lt;/p&gt;

&lt;div style=&quot;border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px&quot;&gt;
  &lt;div style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;
    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #606060&quot;&gt;   1:&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;void&lt;/span&gt; cancelButton_Click(&lt;span style=&quot;color: #0000ff&quot;&gt;object&lt;/span&gt; sender, EventArgs e)&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #606060&quot;&gt;   2:&lt;/span&gt; {&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #606060&quot;&gt;   3:&lt;/span&gt;     tokenSource.Cancel();&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #606060&quot;&gt;   4:&lt;/span&gt; }&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Now that we have a token in all of our Tasks and threads that will tell us when Bob clicks Cancel, we need to gracefully shutdown all of those background threads and what’s spawning them.&lt;/p&gt;

&lt;p&gt;For the Parallel.For loop, we need to get the ParallelOptions down into the doWork method itself, because we want to be able to interrupt the prime number loop itself:&lt;/p&gt;

&lt;div style=&quot;border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px&quot;&gt;
  &lt;div style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;
    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;Parallel.For(0, 100, options, (i) =&amp;gt;&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;{&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;    doWork(i, options);&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;});&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Once there, we can use the CancellationToken property to break out of the process when it’s cancelled:&lt;/p&gt;

&lt;div style=&quot;border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px&quot;&gt;
  &lt;div style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;
    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;void&lt;/span&gt; doWork(&lt;span style=&quot;color: #0000ff&quot;&gt;int&lt;/span&gt; instance, ParallelOptions options)&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt; {&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;     Stopwatch watch = Stopwatch.StartNew();&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;     &lt;span style=&quot;color: #0000ff&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #0000ff&quot;&gt;int&lt;/span&gt; i = 3; i &amp;lt; 30000; i++) &lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;     {&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;         &lt;span style=&quot;color: #0000ff&quot;&gt;if&lt;/span&gt; (isPrime(i));&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;         options.CancellationToken.ThrowIfCancellationRequested();&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;     } &lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;     watch.Stop();&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;     updateList(String.Format(&lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;{0} took {1} milliseconds&amp;quot;&lt;/span&gt;, instance, watch.ElapsedMilliseconds));&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&amp;#160;&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt; }&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;This method throws an exception, so you should catch that and use it to clean up after cancelled tasks.&lt;/p&gt;

&lt;div style=&quot;border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px&quot;&gt;
  &lt;div style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;
    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;try&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt; {&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;     Parallel.For(0, 100, options, (i) =&amp;gt;&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;      {&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;          &lt;span style=&quot;color: #0000ff&quot;&gt;try&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;          {&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;              doWork(i, options);&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;          }&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;          &lt;span style=&quot;color: #0000ff&quot;&gt;catch&lt;/span&gt; (OperationCanceledException ex)&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;          {&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;              &lt;span style=&quot;color: #008000&quot;&gt;// clean up iteration&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;          }&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;      });&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt; }&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;catch&lt;/span&gt; (OperationCanceledException ex)&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt; {&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;     &lt;span style=&quot;color: #008000&quot;&gt;// clean up loop&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt; }&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Bob’s happy with this latest version.&amp;#160; It satisfies both reasons to parallelize or multi-thread an application: Performance and User Experience.&amp;#160; Bob’s experience is improved because he’s able to continue work immediately after clicking on the Go button and doesn’t have to wait at all, and the entire process’ execution time has improved from over fifteen seconds to under four (on a quadcore PC).&amp;#160; Even I’m happy, because I can now send Bob an invoice and get paid.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://lovethedot.s3.amazonaws.com/LoveTheDot.ParallelForExample.zip&quot;&gt;Download Project Source Code&lt;/a&gt;&lt;/p&gt;  </content><link rel='replies' type='application/atom+xml' href='http://www.lovethedot.net/feeds/3706047076505006025/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7622136255348663693&amp;postID=3706047076505006025' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7622136255348663693/posts/default/3706047076505006025'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7622136255348663693/posts/default/3706047076505006025'/><link rel='alternate' type='text/html' href='http://www.lovethedot.net/2010/06/parallel-programming-in-net-40-and.html' title='Parallel Programming in .Net 4.0 and VS2010: Part II – WinForms, Tasks and Service Level Agreements'/><author><name>Paul Jackson</name><uri>http://www.blogger.com/profile/07495739164094993738</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='22' src='http://2.bp.blogspot.com/_d6BPne4gY9w/SdfNBxLRjPI/AAAAAAAAAjc/A7lJO7kwbT0/S220/DOLPHIN1.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh3.ggpht.com/_d6BPne4gY9w/TAhJZBFSe5I/AAAAAAAABME/ovoQoXPwDZI/s72-c/image_thumb%5B1%5D.png?imgmax=800" height="72" width="72"/><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7622136255348663693.post-2360437932513166779</id><published>2010-02-09T16:30:00.001-08:00</published><updated>2010-02-09T16:30:50.652-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term=".net"/><category scheme="http://www.blogger.com/atom/ns#" term=".Net 4.0"/><category scheme="http://www.blogger.com/atom/ns#" term="manycore"/><category scheme="http://www.blogger.com/atom/ns#" term="multi-threaded"/><category scheme="http://www.blogger.com/atom/ns#" term="parallel computing"/><category scheme="http://www.blogger.com/atom/ns#" term="parallel extensions library"/><category scheme="http://www.blogger.com/atom/ns#" term="Visual Studio 2010"/><category scheme="http://www.blogger.com/atom/ns#" term="work of the devil"/><title type='text'>Parallel Programming in .Net 4.0 and VS2010: Part I – The Parallel Task Library (Parallel.For, Parallel.Foreach() and Invoke())</title><content type='html'>&lt;p&gt;With the availability this week of the Visual Studio 2010 RC, it’s time to update the parallel posts from last year to cover changes in the API – so this is much the same information as presented in the &lt;a href=&quot;http://www.lovethedot.net/2009/01/parallel-programming-in-net-40-and.html&quot; target=&quot;_blank&quot;&gt;original article&lt;/a&gt;, but it’s updated for the Visual Studio 2010 release candidate.&lt;/p&gt;  &lt;p&gt;In this article, we’re going to look at the Parallel Task Library and what it makes available for parallelizing &lt;em&gt;for&lt;/em&gt; and &lt;em&gt;foreach&lt;/em&gt; loops.&lt;/p&gt;  &lt;h4&gt;Parallel.For()&lt;/h4&gt;  &lt;p&gt;Starting with a simple, single-threaded application that does some work a few times:&lt;/p&gt;  &lt;div style=&quot;border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px&quot;&gt;   &lt;div style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;     &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #0000ff&quot;&gt;int&lt;/span&gt; i = 0; i &amp;lt; 100; i++)&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;{&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;    var watch = Stopwatch.StartNew();&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;    doWork();&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;    watch.Stop();&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;    Console.WriteLine(&lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;{0} took {1} milliseconds&amp;quot;&lt;/span&gt;, i, watch.ElapsedMilliseconds);&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;}&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&amp;#160;&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;Console.ReadLine();&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;And where the doWork() method is simply a really bad way of determining the prime numbers under 30000:&lt;/p&gt;

&lt;div style=&quot;border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px&quot;&gt;
  &lt;div style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;
    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;void&lt;/span&gt; doWork()&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt; {&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;     &lt;span style=&quot;color: #0000ff&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #0000ff&quot;&gt;int&lt;/span&gt; i = 3; i &amp;lt; 30000; i++)&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;     {&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;         &lt;span style=&quot;color: #0000ff&quot;&gt;if&lt;/span&gt; (isPrime(i))&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;             ;&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;     }&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt; }&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&amp;#160;&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;bool&lt;/span&gt; isPrime(&lt;span style=&quot;color: #0000ff&quot;&gt;int&lt;/span&gt; i)&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt; {&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;     &lt;span style=&quot;color: #0000ff&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #0000ff&quot;&gt;int&lt;/span&gt; j = 2; j &amp;lt;= (i/2); j++)&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;     {&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;         &lt;span style=&quot;color: #0000ff&quot;&gt;if&lt;/span&gt; ((i % j) == 0)&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;             &lt;span style=&quot;color: #0000ff&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;false&lt;/span&gt;;&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;     }&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&amp;#160;&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;     &lt;span style=&quot;color: #0000ff&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;true&lt;/span&gt;;&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt; }&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;The purpose of the doWork() method, of course, is just to give the CPU something to do – which it does, consistently taking about 147 milliseconds for each iteration on a system with a 2.27 GHz quadcore Q9100 processor.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://lh3.ggpht.com/_d6BPne4gY9w/S3H-KfqwIjI/AAAAAAAAAnI/GsfEoIzOVg0/s1600-h/image%5B2%5D.png&quot;&gt;&lt;img style=&quot;border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;http://lh3.ggpht.com/_d6BPne4gY9w/S3H-KoX7GJI/AAAAAAAAAnM/U-Q1F6fnU14/image_thumb.png?imgmax=800&quot; width=&quot;244&quot; height=&quot;184&quot; /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Although there’s some activity on all four cores as this runs, the total CPU usage stays between 20% and 25%, never making full use of the processor’s four cores:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://lh4.ggpht.com/_d6BPne4gY9w/S3H-KxYHoLI/AAAAAAAAAnQ/5GfD4oqeXYc/s1600-h/image%5B6%5D.png&quot;&gt;&lt;img style=&quot;border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;http://lh4.ggpht.com/_d6BPne4gY9w/S3H-LO1ar3I/AAAAAAAAAnU/_bk2qF0z21Q/image_thumb%5B2%5D.png?imgmax=800&quot; width=&quot;364&quot; height=&quot;106&quot; /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Although the CPU and operating system will cooperate to send work from multiple applications to the cores in such a way as to make as much use of them as possible, a single-threaded application by itself will never get much above one core’s worth of the CPU’s total power.&amp;#160; &lt;/p&gt;

&lt;p&gt;To access that power for our applications, we have to create multiple threads – and .Net 4 makes it very easy to do so.&amp;#160; &lt;/p&gt;

&lt;p&gt;New in .Net 4 is the System.Threading.Tasks namespace which contains the Parallel class.&amp;#160; This new class has some static methods which allow us to change the code slightly to parallelize* it:&lt;/p&gt;

&lt;div style=&quot;border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px&quot;&gt;
  &lt;div style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;
    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #008000&quot;&gt;//for (int i = 0; i &amp;lt; 100; i++)&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;Parallel.For(0, 100, (i) =&amp;gt;&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;    {&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;        var watch = Stopwatch.StartNew();&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;        doWork();&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;        watch.Stop();&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;        Console.WriteLine(&lt;span style=&quot;color: #006080&quot;&gt;&amp;quot;{0} took {1} milliseconds&amp;quot;&lt;/span&gt;, i, watch.ElapsedMilliseconds);&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;    }&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;);&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Parallel.For has multiple overloads, but at its most basic (above) it takes a &lt;em&gt;from&lt;/em&gt; integer (inclusive), a &lt;em&gt;to &lt;/em&gt;integer (exclusive) and a delegate (in this case a lambda expression).&amp;#160; The step defaults to 1.&lt;/p&gt;

&lt;p&gt;The effect of this small change is dramatic.&amp;#160; The CPU utilization will now spike to 100% when the application is run:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://lh4.ggpht.com/_d6BPne4gY9w/S3H-Ls4wQaI/AAAAAAAAAnY/tQbjlza897g/s1600-h/image%5B11%5D.png&quot;&gt;&lt;img style=&quot;border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;http://lh5.ggpht.com/_d6BPne4gY9w/S3H-L8ckYOI/AAAAAAAAAnc/ZqFHzrvyxt4/image_thumb%5B5%5D.png?imgmax=800&quot; width=&quot;336&quot; height=&quot;92&quot; /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;And the total runtime for the 100 iterations drops from 14.7 seconds to 4.3 seconds – a huge increase in performance because we’re now making full use of the processor’s four cores.&lt;/p&gt;

&lt;p&gt;A look at the Visual Studio debugger’s Thread window (Debug | Windows | Threads) shows what made the difference.&amp;#160; When executing the first version of the code, with the traditional for-loop, only a single thread is executing at any one time:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://lh5.ggpht.com/_d6BPne4gY9w/S3H-MNuP2nI/AAAAAAAAAng/9G58NRZxP9s/s1600-h/image%5B16%5D.png&quot;&gt;&lt;img style=&quot;border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;http://lh3.ggpht.com/_d6BPne4gY9w/S3H-MdOUpBI/AAAAAAAAAnk/Zl-EpLG5nzk/image_thumb%5B8%5D.png?imgmax=800&quot; width=&quot;722&quot; height=&quot;225&quot; /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;But the change to Parallel.For results in multiple threads doing the work:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://lh6.ggpht.com/_d6BPne4gY9w/S3H-M5iFgGI/AAAAAAAAAno/aRnAy9bAnU0/s1600-h/image%5B21%5D.png&quot;&gt;&lt;img style=&quot;border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;http://lh4.ggpht.com/_d6BPne4gY9w/S3H-NRXN4AI/AAAAAAAAAns/y8m-u0OQD8Y/image_thumb%5B11%5D.png?imgmax=800&quot; width=&quot;733&quot; height=&quot;314&quot; /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;In this case, five threads are simultaneously executing iterations of the work (the main application thread and four worker threads).&amp;#160; The exact number of threads used for parallelization is determined by .Net based on the number of cores available (there are some advanced options for controlling this, but careful consideration should be given before doing so).&lt;/p&gt;

&lt;p&gt;A comparison of the output of both versions does show a couple of important differences that you should consider before parallelizing your code:&lt;/p&gt;

&lt;table border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;2&quot; width=&quot;300&quot;&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign=&quot;top&quot; width=&quot;150&quot;&gt;
        &lt;p align=&quot;center&quot;&gt;&lt;a href=&quot;http://lh6.ggpht.com/_d6BPne4gY9w/S3H-Nv3KnnI/AAAAAAAAAnw/KDUq_h_qKfQ/s1600-h/image%5B24%5D.png&quot;&gt;&lt;img style=&quot;border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;http://lh6.ggpht.com/_d6BPne4gY9w/S3H-N0m1NQI/AAAAAAAAAn0/-FkHeOc-_kA/image_thumb%5B12%5D.png?imgmax=800&quot; width=&quot;215&quot; height=&quot;244&quot; /&gt;&lt;/a&gt; for-loop&lt;/p&gt;
      &lt;/td&gt;

      &lt;td valign=&quot;top&quot; width=&quot;150&quot;&gt;
        &lt;p align=&quot;center&quot;&gt;&lt;a href=&quot;http://lh3.ggpht.com/_d6BPne4gY9w/S3H-OARNwlI/AAAAAAAAAn4/ro5F-fec3zA/s1600-h/image%5B27%5D.png&quot;&gt;&lt;img style=&quot;border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;http://lh5.ggpht.com/_d6BPne4gY9w/S3H-ObUG7wI/AAAAAAAAAn8/ZU6AJdQ6epc/image_thumb%5B13%5D.png?imgmax=800&quot; width=&quot;216&quot; height=&quot;244&quot; /&gt;&lt;/a&gt; Parallel.For&lt;/p&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;The first consideration is performance.&amp;#160; Although the total performance improved from 14-seconds to four, the time spent in each iteration has increased and become less predictable.&amp;#160; In a single-threaded, for-loop each iteration takes a consistent 147-milliseconds, but the parallel implementation varies from 147 to over 300-milliseconds.&amp;#160; This is due to overhead associated with the parallelization and the potential for threads to be swapped out by the operating system to provide CPU cycles to other applications.&lt;/p&gt;

&lt;p&gt;Another consideration is ordering of the work.&amp;#160; As you can see from the screenshots above, the single-threaded example performs the work sequentially.&amp;#160; Each time through the for loop does its work and completes before the next starts.&amp;#160; But when this is parallelized, the order of completion can’t be guaranteed.&amp;#160; As the work is off-loaded to seven worker threads (in this example), each of those threads could complete its work and get the next task at any time.&amp;#160; So parallelizing isn’t an option (or is a more complex option) when the order of execution matters to your application.&lt;/p&gt;

&lt;h4&gt;Parallel.ForEach&lt;/h4&gt;

&lt;p&gt;The Parallel.ForEach() method follows the same pattern:&lt;/p&gt;

&lt;div style=&quot;border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px&quot;&gt;
  &lt;div style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;
    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;List&amp;lt;&lt;span style=&quot;color: #0000ff&quot;&gt;int&lt;/span&gt;&amp;gt; list = &lt;span style=&quot;color: #0000ff&quot;&gt;new&lt;/span&gt; List&amp;lt;&lt;span style=&quot;color: #0000ff&quot;&gt;int&lt;/span&gt;&amp;gt;();&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #008000&quot;&gt;// populate list&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;Parallel.ForEach(list, (item) =&amp;gt;&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;    {&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;        &lt;span style=&quot;color: #008000&quot;&gt;// parallel work here&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;    }&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;);&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h4&gt;Parallel.Invoke&lt;/h4&gt;

&lt;p&gt;Parallel.For() and Parallel.ForEach() are useful if you have collections you need to act on or a known number of times you have to execute the same code, but what about when you have several different things (methods) you need to do?&amp;#160; For that, we have Parallel.Invoke().&lt;/p&gt;

&lt;p&gt;Parallel.Invoke() simply executes, in parallel, a list of methods passed to it:&lt;/p&gt;

&lt;div style=&quot;border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px&quot;&gt;
  &lt;div style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;
    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;void&lt;/span&gt; Main(&lt;span style=&quot;color: #0000ff&quot;&gt;string&lt;/span&gt;[] args)&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;{&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;    Parallel.Invoke(A, B, C, D, E);&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;    Console.ReadLine();&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;}&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;void&lt;/span&gt; A(){}&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;void&lt;/span&gt; B(){}&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;void&lt;/span&gt; C(){}&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;void&lt;/span&gt; D(){}&lt;/pre&gt;

    &lt;pre style=&quot;border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px&quot;&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;void&lt;/span&gt; E(){}&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Methods A(), B(), C(), D() and E() will be assigned to worker threads as they become available and execute in parallel.&amp;#160; As with the other methods, there are no guarantees about the order of execution.&lt;/p&gt;

&lt;h4&gt;Conclusion&lt;/h4&gt;

&lt;p&gt;The Parallel Extensions in .Net 4.0 are going give developers a much easier and consistent way to parallelize their applications.&amp;#160; The library greatly insulates us from the complexity and inner plumbing of the parallel world, but still have responsibilities to use them properly.&amp;#160; Hard questions and issues will remain around the architecture, design and implementation of parallelization in our applications, but Microsoft is aware of this and is busy providing us with more resources than just the tools in this library.&amp;#160; The &lt;a href=&quot;http://msdn.microsoft.com/en-us/concurrency/default.aspx&quot;&gt;Parallel Computing Developer Center&lt;/a&gt; has a wealth of whitepapers and presentations on these topics.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://lovethedot.s3.amazonaws.com/LoveTheDot.Demo.ParallelFor.zip&quot; target=&quot;_blank&quot;&gt;Source code for the Parallel.For example&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;font size=&quot;1&quot;&gt;* I’d really like to track down and &lt;strike&gt;beat&lt;/strike&gt; speak strongly to the &lt;strike&gt;bastard&lt;/strike&gt; person who coined the term “parallelize” because every time I talk about this feature I invariably drop a syllable and tell my audience how easy .Net 4 makes it for you to paralyze your code**.&lt;/font&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;font size=&quot;1&quot;&gt;** On the other hand, if you don’t keep the pitfalls of &lt;strike&gt;the work of the devil&lt;/strike&gt; multi-threaded programming in mind, your code &lt;em&gt;will&lt;/em&gt; wind up paralyzed, so it’s still an accurate statement.&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt;  </content><link rel='replies' type='application/atom+xml' href='http://www.lovethedot.net/feeds/2360437932513166779/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7622136255348663693&amp;postID=2360437932513166779' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7622136255348663693/posts/default/2360437932513166779'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7622136255348663693/posts/default/2360437932513166779'/><link rel='alternate' type='text/html' href='http://www.lovethedot.net/2010/02/parallel-programming-in-net-40-and.html' title='Parallel Programming in .Net 4.0 and VS2010: Part I – The Parallel Task Library (Parallel.For, Parallel.Foreach() and Invoke())'/><author><name>Paul Jackson</name><uri>http://www.blogger.com/profile/07495739164094993738</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='22' src='http://2.bp.blogspot.com/_d6BPne4gY9w/SdfNBxLRjPI/AAAAAAAAAjc/A7lJO7kwbT0/S220/DOLPHIN1.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh3.ggpht.com/_d6BPne4gY9w/S3H-KoX7GJI/AAAAAAAAAnM/U-Q1F6fnU14/s72-c/image_thumb.png?imgmax=800" height="72" width="72"/><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7622136255348663693.post-775372382689909365</id><published>2009-05-01T14:50:00.001-07:00</published><updated>2009-05-01T14:50:48.407-07:00</updated><title type='text'>The Blogger Next Door - Update</title><content type='html'>&lt;p&gt;It’s been about a month since I made my post about &lt;a href=&quot;http://www.lovethedot.net/2009/03/blogger-next-door.html&quot;&gt;The Blogger Next Door&lt;/a&gt;, referring to Bil Simser’s &lt;a href=&quot;http://weblogs.asp.net/bsimser/archive/2009/03/27/the-girl-next-door.aspx&quot;&gt;The Girl Next Door&lt;/a&gt; post – well, Bil has now posted an &lt;a href=&quot;http://weblogs.asp.net/bsimser/archive/2009/04/29/follow-up-the-girl-next-door-aka-laptop-for-nat.aspx&quot;&gt;update&lt;/a&gt;, including pictures of Natalie receiving her new laptop with &lt;a href=&quot;http://www.nuance.com&quot;&gt;Dragon Naturally Speaking&lt;/a&gt; at her birthday party this week.&amp;#160; On top of the laptop and software, Bil’s post raised $2100 to help Natalie’s family with the medical expenses.&amp;#160; &lt;/p&gt;  &lt;h2&gt;A Bit About Nuance Communications and Dragon Naturally Speaking&lt;/h2&gt;  &lt;p&gt;One of the things I find most impressive about the result is the actions of Nuance Communications, makers of &lt;a href=&quot;http://www.nuance.com&quot;&gt;Dragon Naturally Speaking&lt;/a&gt;.&amp;#160; &lt;/p&gt;  &lt;p&gt;After reading Bil’s original post and making my own, I gave in to a bit of a whim and faxed a letter to the CEO of Nuance, referencing Bil’s blog and briefly describing the situation.&amp;#160; I faxed that letter after close of business on a Friday afternoon.&lt;/p&gt;  &lt;p&gt;Before 10:00 AM Monday morning, I had received an email from the Dragon Naturally Speaking Product Manager telling me that they had emailed Bil to offer a free copy of the software.&lt;/p&gt;  &lt;p&gt;They really didn’t have to respond at all and certainly not that quickly, but they did – and it wasn’t because of any great amount of publicity they’d get for the deed.&amp;#160; There were no national news vans hovering around this story – they did it because they were able to help and wanted to.&amp;#160; That’s the best reason.&lt;/p&gt;  &lt;p&gt;So, for what it’s worth coming from my little blog, the folks at Nuance are a stand-up group and I know I’ll be looking to them on any project I work on that might benefit from their products.&amp;#160;&amp;#160; &lt;/p&gt;&lt;div class=&quot;wlWriterHeaderFooter&quot; style=&quot;text-align:left; margin:0px; padding:4px 4px 4px 4px;&quot;&gt;&lt;script type=&quot;text/javascript&quot;&gt;var dzone_url = &#39;http://www.lovethedot.net/2009/05/blogger-next-door-update.html&#39;;&lt;/script&gt;&lt;script type=&quot;text/javascript&quot;&gt;var dzone_title = &#39;The Blogger Next Door - Update&#39;;&lt;/script&gt;&lt;script type=&quot;text/javascript&quot;&gt;var dzone_blurb = &#39;The Blogger Next Door - Update&#39;;&lt;/script&gt;&lt;script type=&quot;text/javascript&quot;&gt;var dzone_style = &#39;2&#39;;&lt;/script&gt;&lt;script language=&quot;javascript&quot; src=&quot;http://widgets.dzone.com/widgets/zoneit.js&quot;&gt;&lt;/script&gt; &lt;/div&gt;  </content><link rel='replies' type='application/atom+xml' href='http://www.lovethedot.net/feeds/775372382689909365/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7622136255348663693&amp;postID=775372382689909365' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7622136255348663693/posts/default/775372382689909365'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7622136255348663693/posts/default/775372382689909365'/><link rel='alternate' type='text/html' href='http://www.lovethedot.net/2009/05/blogger-next-door-update.html' title='The Blogger Next Door - Update'/><author><name>Paul Jackson</name><uri>http://www.blogger.com/profile/07495739164094993738</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='22' src='http://2.bp.blogspot.com/_d6BPne4gY9w/SdfNBxLRjPI/AAAAAAAAAjc/A7lJO7kwbT0/S220/DOLPHIN1.JPG'/></author><thr:total>4</thr:total></entry></feed>