<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Liang&#039;s Vision &#187; Dot Net</title>
	<atom:link href="http://www.zhang-liang.com/articles/category/dot-net/feed" rel="self" type="application/rss+xml" />
	<link>http://www.zhang-liang.com</link>
	<description>如切如磋，如琢如磨</description>
	<lastBuildDate>Mon, 01 Aug 2011 01:14:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>A very detailed tutorial about .Net multithreading</title>
		<link>http://www.zhang-liang.com/articles/78</link>
		<comments>http://www.zhang-liang.com/articles/78#comments</comments>
		<pubDate>Wed, 10 Mar 2010 13:13:32 +0000</pubDate>
		<dc:creator>Liang Zhang</dc:creator>
				<category><![CDATA[Dot Net]]></category>

		<guid isPermaLink="false">http://www.zhang-liang.com/?p=78</guid>
		<description><![CDATA[Worth reading:  Multi-threading in .NET]]></description>
			<content:encoded><![CDATA[<p>Worth reading:  <a href="http://www.yoda.arachsys.com/csharp/threads/index.shtml">Multi-threading in .NET</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.zhang-liang.com/articles/78/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A TimedLock</title>
		<link>http://www.zhang-liang.com/articles/76</link>
		<comments>http://www.zhang-liang.com/articles/76#comments</comments>
		<pubDate>Tue, 09 Mar 2010 15:40:28 +0000</pubDate>
		<dc:creator>Liang Zhang</dc:creator>
				<category><![CDATA[Dot Net]]></category>

		<guid isPermaLink="false">http://www.zhang-liang.com/?p=76</guid>
		<description><![CDATA[The original article is from here Because the nice-looking .Net lock keyword is translated with try{Monitor.Enter(obj);}finally{Monitor.Exit(obj)}, there is no timeout for Monitor.Enter, that may make it easier to cause some deadlock issues. That&#8217;s why Ian Griffiths invented his new lock. He and some other guys discussed a lot about how to improve the lock both [...]]]></description>
			<content:encoded><![CDATA[<p>The original article is from<a href="http://www.interact-sw.co.uk/iangblog/2004/04/26/yetmoretimedlocking"> here</a></p>
<p>Because the nice-looking .Net lock keyword is translated with try{Monitor.Enter(obj);}finally{Monitor.Exit(obj)}, there is no timeout for Monitor.Enter, that may make it easier to cause some deadlock issues. That&#8217;s why <a href="http://www.interact-sw.co.uk/iangblog/">Ian Griffiths</a> invented his new lock. He and some other guys discussed a lot about how to improve the lock both in efficiency and usability. I am not going to talk much.</p>
<p>the code is like below:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Threading</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// Thanks to Eric Gunnerson for recommending this be a struct rather</span>
<span style="color: #008080; font-style: italic;">// than a class - avoids a heap allocation.</span>
<span style="color: #008080; font-style: italic;">// Thanks to Change Gillespie and Jocelyn Coulmance for pointing out</span>
<span style="color: #008080; font-style: italic;">// the bugs that then crept in when I changed it to use struct...</span>
<span style="color: #008080; font-style: italic;">// Thanks to John Sands for providing the necessary incentive to make</span>
<span style="color: #008080; font-style: italic;">// me invent a way of using a struct in both release and debug builds</span>
<span style="color: #008080; font-style: italic;">// without losing the debug leak tracking.</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">struct</span> TimedLock <span style="color: #008000;">:</span> IDisposable
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> TimedLock <span style="color: #0600FF; font-weight: bold;">Lock</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> o<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">Lock</span> <span style="color: #008000;">&#40;</span>o, TimeSpan<span style="color: #008000;">.</span><span style="color: #0000FF;">FromSeconds</span> <span style="color: #008000;">&#40;</span><span style="color: #FF0000;">10</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> TimedLock <span style="color: #0600FF; font-weight: bold;">Lock</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> o, TimeSpan timeout<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        TimedLock tl <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> TimedLock <span style="color: #008000;">&#40;</span>o<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>Monitor<span style="color: #008000;">.</span><span style="color: #0000FF;">TryEnter</span> <span style="color: #008000;">&#40;</span>o, timeout<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
<span style="color: #008080;">#if DEBUG</span>
            <span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GC</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SuppressFinalize</span><span style="color: #008000;">&#40;</span>tl<span style="color: #008000;">.</span><span style="color: #0000FF;">leakDetector</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008080;">#endif</span>
            <span style="color: #0600FF; font-weight: bold;">throw</span> <span style="color: #008000;">new</span> LockTimeoutException <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">return</span> tl<span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">private</span> TimedLock <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> o<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        target <span style="color: #008000;">=</span> o<span style="color: #008000;">;</span>
<span style="color: #008080;">#if DEBUG</span>
        leakDetector <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Sentinel<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008080;">#endif</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">object</span> target<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> Dispose <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        Monitor<span style="color: #008000;">.</span><span style="color: #0000FF;">Exit</span> <span style="color: #008000;">&#40;</span>target<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// It's a bad error if someone forgets to call Dispose,</span>
        <span style="color: #008080; font-style: italic;">// so in Debug builds, we put a finalizer in to detect</span>
        <span style="color: #008080; font-style: italic;">// the error. If Dispose is called, we suppress the</span>
        <span style="color: #008080; font-style: italic;">// finalizer.</span>
<span style="color: #008080;">#if DEBUG</span>
        GC<span style="color: #008000;">.</span><span style="color: #0000FF;">SuppressFinalize</span><span style="color: #008000;">&#40;</span>leakDetector<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008080;">#endif</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #008080;">#if DEBUG</span>
    <span style="color: #008080; font-style: italic;">// (In Debug mode, we make it a class so that we can add a finalizer</span>
    <span style="color: #008080; font-style: italic;">// in order to detect when the object is not freed.)</span>
    <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">class</span> Sentinel
    <span style="color: #008000;">&#123;</span>
        ~Sentinel<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// If this finalizer runs, someone somewhere failed to</span>
            <span style="color: #008080; font-style: italic;">// call Dispose, which means we've failed to leave</span>
            <span style="color: #008080; font-style: italic;">// a monitor!</span>
            <span style="color: #000000;">System.<span style="color: #0000FF;">Diagnostics</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">Debug</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Fail</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Undisposed lock&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0600FF; font-weight: bold;">private</span> Sentinel leakDetector<span style="color: #008000;">;</span>
<span style="color: #008080;">#endif</span>
&nbsp;
<span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> LockTimeoutException <span style="color: #008000;">:</span> ApplicationException
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> LockTimeoutException <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">:</span> <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Timeout waiting for lock&quot;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.zhang-liang.com/articles/76/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Share:Dot Net WCF Training</title>
		<link>http://www.zhang-liang.com/articles/39</link>
		<comments>http://www.zhang-liang.com/articles/39#comments</comments>
		<pubDate>Thu, 12 Feb 2009 09:55:00 +0000</pubDate>
		<dc:creator>Liang Zhang</dc:creator>
				<category><![CDATA[Dot Net]]></category>

		<guid isPermaLink="false">http://www.zhang-liang.com/?p=39</guid>
		<description><![CDATA[Dot Net Training Wcf Dot Net35 REST, JSON and RSS with WCF 3.5 View more presentations from Rob Windsor. (tags: wcf rest)]]></description>
			<content:encoded><![CDATA[<div style="width: 425px; text-align: left;" id="__ss_443947"><a style="margin: 12px 0pt 3px; font-family: Helvetica,Arial,Sans-serif; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: normal; font-size-adjust: none; font-stretch: normal; display: block; text-decoration: underline;" href="http://www.slideshare.net/spushpak/dot-net-training-wcf-dot-net35?type=powerpoint" title="Dot Net Training Wcf Dot Net35">Dot Net Training Wcf Dot Net35</a><object style="margin: 0px;" width="425" height="355"><param name="movie" value="http://static.slideshare.net/swf/ssplayer2.swf?doc=dotnettrainingwcfdotnet35-1212486620973580-9&amp;stripped_title=dot-net-training-wcf-dot-net35"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><embed src="http://static.slideshare.net/swf/ssplayer2.swf?doc=dotnettrainingwcfdotnet35-1212486620973580-9&amp;stripped_title=dot-net-training-wcf-dot-net35" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object></p>
<p>
<div style="width: 425px; text-align: left;" id="__ss_848228"><a style="margin: 12px 0pt 3px; font-family: Helvetica,Arial,Sans-serif; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: normal; font-size-adjust: none; font-stretch: normal; display: block; text-decoration: underline;" href="http://www.slideshare.net/rob.windsor/rest-json-and-rss-with-wcf-35-presentation?type=presentation" title="REST, JSON and RSS with WCF 3.5">REST, JSON and RSS with WCF 3.5</a><object style="margin: 0px;" width="425" height="355"><param name="movie" value="http://static.slideshare.net/swf/ssplayer2.swf?doc=rest-json-and-rss-with-windows-communication-foundation-35-1229383620110154-1&amp;stripped_title=rest-json-and-rss-with-wcf-35-presentation"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><embed src="http://static.slideshare.net/swf/ssplayer2.swf?doc=rest-json-and-rss-with-windows-communication-foundation-35-1229383620110154-1&amp;stripped_title=rest-json-and-rss-with-wcf-35-presentation" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="font-size: 11px; font-family: tahoma,arial; height: 26px; padding-top: 2px;">View more <a style="text-decoration: underline;" href="http://www.slideshare.net/">presentations</a> from <a style="text-decoration: underline;" href="http://www.slideshare.net/rob.windsor">Rob Windsor</a>. (tags: <a style="text-decoration: underline;" href="http://slideshare.net/tag/wcf">wcf</a> <a style="text-decoration: underline;" href="http://slideshare.net/tag/rest">rest</a>)</div>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.zhang-liang.com/articles/39/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

