<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type='text/xsl' href='http://saguiitay.spaces.live.com/mmm2008-05-17_13.22/rsspretty.aspx?rssquery=en-US;http%3a%2f%2fsaguiitay.spaces.live.com%2fcategory%2fGeneral%2bDevelopment%2ffeed.rss' version='1.0'?><rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:msn="http://schemas.microsoft.com/msn/spaces/2005/rss" xmlns:live="http://schemas.microsoft.com/live/spaces/2006/rss" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Itay's space: General Development</title><description /><link>http://saguiitay.spaces.live.com/?_c11_BlogPart_BlogPart=blogview&amp;_c=BlogPart&amp;partqs=catGeneral%2bDevelopment</link><language>en-US</language><pubDate>Wed, 23 Jul 2008 03:21:52 GMT</pubDate><lastBuildDate>Wed, 23 Jul 2008 03:21:52 GMT</lastBuildDate><generator>Microsoft Spaces v1.1</generator><docs>http://www.rssboard.org/rss-specification</docs><ttl>60</ttl><cf:parentRSS>http://saguiitay.spaces.live.com/blog/feed.rss</cf:parentRSS><live:type>blogcategory</live:type><live:identity><live:id>4287375271627483618</live:id><live:alias>saguiitay</live:alias></live:identity><cf:listinfo><cf:group ns="http://schemas.microsoft.com/live/spaces/2006/rss" element="typelabel" label="Type" /><cf:group ns="http://schemas.microsoft.com/live/spaces/2006/rss" element="tag" label="Tag" /><cf:group element="category" label="Category" /><cf:sort element="pubDate" label="Date" data-type="date" default="true" /><cf:sort element="title" label="Title" data-type="string" /><cf:sort ns="http://purl.org/rss/1.0/modules/slash/" element="comments" label="Comments" data-type="number" /></cf:listinfo><item><title>The Interlocked class</title><link>http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!658.entry</link><description>&lt;div&gt;
&lt;p&gt;Working with threads and counters can because a really pain if you do not take care. Fortunetly for us, .Net supplies us with a couple of methods that can make our life a little bit easier. The class &lt;code&gt;Interlocked&lt;/code&gt;, which can be found in &lt;code&gt;System.Thread&lt;/code&gt; allows you to increment, decrement, and set the value of an &lt;code&gt;int&lt;/code&gt; or &lt;code&gt;long&lt;/code&gt; as an atomic action, thus preventing race conditions where multiple threads update the same counter at the same time.
&lt;p&gt;The first methods are of course, &lt;code&gt;Increment()&lt;/code&gt; and &lt;code&gt;Decrement()&lt;/code&gt;, both accepting an &lt;code&gt;int&lt;/code&gt; or &lt;code&gt;long&lt;/code&gt; variable and update it as requested.
&lt;p&gt;The next method is the &lt;code&gt;Exchange()&lt;/code&gt;, which allow you to set the value of either an &lt;code&gt;int&lt;/code&gt;, a &lt;code&gt;long&lt;/code&gt; or &lt;code&gt;object&lt;/code&gt; variable, by passing it the variable by reference, and the next requested value.
&lt;p&gt;Another interesting method in the &lt;code&gt;CompareExchange()&lt;/code&gt;. This method checks if the value of the variable is as expected, and only then update it. The methos returns the current value of the variable, whether it was updated or not, allowing you to redo you calculations if the value changed while you were calculating the new value. Below is an example take from &lt;a href="http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemthreadinginterlockedclasscompareexchangetopic.asp"&gt;&lt;font color="#333333"&gt;MSDN&lt;/font&gt;&lt;/a&gt;:
&lt;p&gt;&lt;code&gt;&lt;font face="Courier New, Courier, Monospace"&gt;&lt;font color="#0000ff"&gt;public int&lt;/font&gt; AddToTotal(int addend)&lt;br&gt;{&lt;br&gt;     &lt;font color="#0000ff"&gt;int&lt;/font&gt; initialValue, computedValue;&lt;br&gt;     &lt;font color="#0000ff"&gt;do&lt;/font&gt;&lt;br&gt;     {&lt;br&gt;         initialValue = totalValue;&lt;br&gt;         computedValue = initialValue + addend;&lt;br&gt;     }&lt;br&gt;     &lt;font color="#0000ff"&gt;while&lt;/font&gt; (initialValue != Interlocked.CompareExchange(ref totalValue, computedValue, initialValue));&lt;br&gt;     &lt;font color="#0000ff"&gt;return&lt;/font&gt; computedValue;&lt;br&gt;}&lt;/font&gt;&lt;/code&gt;&lt;/div&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=4287375271627483618&amp;page=RSS%3a+The+Interlocked+class&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=saguiitay.spaces.live.com&amp;amp;GT1=saguiitay"&gt;</description><comments>http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!658.entry#comment</comments><guid isPermaLink="true">http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!658.entry</guid><pubDate>Wed, 06 Sep 2006 13:26:23 GMT</pubDate><slash:comments>0</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://saguiitay.spaces.live.com/blog/cns!3B7FD118142669E2!658/comments/feed.rss</wfw:commentRss><wfw:comment>http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!658.entry#comment</wfw:comment><dcterms:modified>2006-09-06T13:26:23Z</dcterms:modified></item><item><title>Writing an IsApplicationRunning method</title><link>http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!655.entry</link><description>&lt;div&gt;
&lt;p&gt;You are welcome to read and vote for my new article at CodeProject:
&lt;p&gt;&lt;a href="http://www.codeproject.com/useritems/IsApplicationRunning.asp"&gt;&lt;font color="#333333"&gt;Writing a Win32 method to find if an application is running&lt;/font&gt;&lt;/a&gt;
&lt;p&gt;The article explains how to write a method to find out if a certain application is running in the backgroud, using the &lt;font face="Courier New, Courier, Monospace"&gt;&lt;code&gt;Process32First&lt;/code&gt; &lt;/font&gt;and &lt;font face="Courier New, Courier, Monospace"&gt;&lt;code&gt;Process32Next&lt;/code&gt; &lt;/font&gt;functions.&lt;/div&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=4287375271627483618&amp;page=RSS%3a+Writing+an+IsApplicationRunning+method&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=saguiitay.spaces.live.com&amp;amp;GT1=saguiitay"&gt;</description><comments>http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!655.entry#comment</comments><guid isPermaLink="true">http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!655.entry</guid><pubDate>Wed, 06 Sep 2006 13:08:17 GMT</pubDate><slash:comments>0</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://saguiitay.spaces.live.com/blog/cns!3B7FD118142669E2!655/comments/feed.rss</wfw:commentRss><wfw:comment>http://saguiitay.spaces.live.com/Blog/cns!3B7FD118142669E2!655.entry#comment</wfw:comment><dcterms:modified>2006-09-06T13:08:17Z</dcterms:modified></item></channel></rss>