<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Vitaly Dilmukhametov</title>
        <link>http://geekswithblogs.net/vitus/Default.aspx</link>
        <description> </description>
        <language>ru-RU</language>
        <copyright>Vitus</copyright>
        <managingEditor>vitus@movaxbx.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <image>
            <title>Vitaly Dilmukhametov</title>
            <url>http://geekswithblogs.net/images/RSS2Image.gif</url>
            <link>http://geekswithblogs.net/vitus/Default.aspx</link>
            <width>77</width>
            <height>60</height>
        </image>
        <item>
            <title>MS Office 365 &amp;ndash; custom domain without MS name servers</title>
            <category>workaround</category>
            <category>hint</category>
            <category>Office 365</category>
            <category>DNS</category>
            <category>Domain</category>
            <category>Exchange</category>
            <link>http://geekswithblogs.net/vitus/archive/2011/07/19/ms-office-365-ndash-custom-domain-without-ms-name-servers.aspx</link>
            <description>&lt;p&gt;I purchased Office 365 subscription recently, and wanted to bind my own domain, because wanted to use e-mail address like &lt;a href="mailto:alias@some_custom_domain.com"&gt;alias@some_custom_domain.com&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If you want to use custom domains, &lt;a href="http://onlinehelp.microsoft.com/en-us/office365-smallbusinesses/gg549203.aspx"&gt;manual page&lt;/a&gt; suggest to change name server records for your domain to &lt;strong&gt;ns1.bdm.microsoftonline.com&lt;/strong&gt; and &lt;strong&gt;ns2.bdm.microsoftonline.com. &lt;/strong&gt;After doing this you can use aliases with your domain for Exchange mail and Lync.&lt;/p&gt;
&lt;p&gt;If you don’t want to change by any reasons name servers for your domain, just go through steps:&lt;/p&gt;
&lt;p&gt;1) open &lt;strong&gt;Domains&lt;/strong&gt; page in your admin&lt;/p&gt;
&lt;p&gt;2) click on your custom domain &lt;em&gt;my_custom_domain.com&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;3) on the domain page click &lt;strong&gt;DNS Dispatcher&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;4) you can see “system’s” Office 365 MX, CNAME, TXT and SRV records (screenshot in my native Russian lang, but I think it’s not a problem to understand):&lt;/p&gt;
&lt;p&gt;&lt;img width="625" height="484" title="image" alt="image" border="0" style="border: 0px currentColor; padding-top: 0px; padding-right: 0px; padding-left: 0px; display: inline; background-image: none;" src="http://geekswithblogs.net/images/geekswithblogs_net/vitus/Windows-Live-Writer/MS-Office-365custom-domain-without_14BBD/image_3.png" /&gt;&lt;/p&gt;
&lt;p&gt;Add this records to your domain, and wait some time (about 10-30 min). After that you can use your custom domain to create users with full access to Office 365 services, and without using MS name servers.&lt;/p&gt;
&lt;p&gt;&lt;font size="3"&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;Warning!&lt;/strong&gt; &lt;/font&gt;&lt;font color="#000000"&gt;&lt;u&gt;This method is NOT suitable for any enterprise customers!! Because if “system” records are changed, your users can’t use one or any services (Exchange, Lync, etc) until you manually fix your domain records.&lt;/u&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;I tried to do it, and it’s working. I use Office 365 privately, so I wake up to a risk.&lt;/p&gt;
&lt;p&gt;Good luck! ;)&lt;/p&gt; &lt;img src="http://geekswithblogs.net/vitus/aggbug/146267.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Vitus</dc:creator>
            <guid>http://geekswithblogs.net/vitus/archive/2011/07/19/ms-office-365-ndash-custom-domain-without-ms-name-servers.aspx</guid>
            <pubDate>Tue, 19 Jul 2011 07:18:08 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/vitus/comments/146267.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/vitus/archive/2011/07/19/ms-office-365-ndash-custom-domain-without-ms-name-servers.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/vitus/comments/commentRss/146267.aspx</wfw:commentRss>
        </item>
        <item>
            <title>[VS2010]: C# statement collapsing</title>
            <category>.NET</category>
            <category>Visual Studio</category>
            <category>hint</category>
            <category>C#</category>
            <category>Visual Studio add-in</category>
            <link>http://geekswithblogs.net/vitus/archive/2011/06/23/vs2010-c-statement-collapsing.aspx</link>
            <description>&lt;p&gt;If you need to explore big amount of another’s C# code, &lt;a href="http://visualstudiogallery.msdn.microsoft.com/4d7e74d7-3d71-4ee5-9ac8-04b76e411ea8"&gt;C# outline add-in&lt;/a&gt; may be helpful. It allow you to collapse statements between &lt;strong&gt;{ &lt;/strong&gt;and &lt;strong&gt;}&lt;/strong&gt;. Here is a sample screenshot:&lt;/p&gt;
&lt;p&gt;&lt;img width="404" height="550" title="image" alt="image" border="0" style="border: 0px currentColor; padding-top: 0px; padding-right: 0px; padding-left: 0px; display: inline; background-image: none;" src="http://geekswithblogs.net/images/geekswithblogs_net/vitus/Windows-Live-Writer/c9219886e517_8C34/image_3.png" /&gt;&lt;/p&gt;
&lt;p&gt;This add-in available for Visual Studio 2010. Also, it’s not compatible with some other plugins like &lt;a href="http://visualstudiogallery.msdn.microsoft.com/6a7a0b57-7059-470d-bcfa-60ceb78dc752?SRC=VSIDE"&gt;Presentation Zoom&lt;/a&gt; – outline nodes displaces, if both installed.&lt;/p&gt; &lt;img src="http://geekswithblogs.net/vitus/aggbug/145961.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Vitus</dc:creator>
            <guid>http://geekswithblogs.net/vitus/archive/2011/06/23/vs2010-c-statement-collapsing.aspx</guid>
            <pubDate>Thu, 23 Jun 2011 17:09:43 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/vitus/comments/145961.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/vitus/archive/2011/06/23/vs2010-c-statement-collapsing.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/vitus/comments/commentRss/145961.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Workaround: build FBX in XNA raise OutOfMemoryException</title>
            <category>XNA</category>
            <category>FBX</category>
            <category>Content pipeline</category>
            <link>http://geekswithblogs.net/vitus/archive/2011/06/20/workaround-build-fbx-in-xna-raise-outofmemoryexception.aspx</link>
            <description>&lt;p&gt;If you try to add large FBX 3D model to the XNA project, and build it, you can get an OutOfMemoryException build error like following:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Error    1    Building content threw OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.     &lt;br /&gt;
   at System.Collections.Generic.List`1.set_Capacity(Int32 value)      &lt;br /&gt;
   at System.Collections.Generic.List`1.EnsureCapacity(Int32 min)      &lt;br /&gt;
   at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)      &lt;br /&gt;
   at Microsoft.Xna.Framework.Content.Pipeline.Graphics.VertexChannel`1.InsertRange(Int32 index, Int32 count)      &lt;br /&gt;
   at Microsoft.Xna.Framework.Content.Pipeline.Graphics.VertexContent.InsertRange(Int32 index, IEnumerable`1 positionIndexCollection)      &lt;br /&gt;
   at Microsoft.Xna.Framework.Content.Pipeline.Graphics.MeshBuilder.AddTriangleVertex(Int32 indexIntoVertexCollection)      &lt;br /&gt;
   at Microsoft.Xna.Framework.Content.Pipeline.MeshConverter.FillNodeWithInfoFromMesh(KFbxNode* fbxNode, String name, KFbxGeometryConverter* geometryConverter)      &lt;br /&gt;
   at Microsoft.Xna.Framework.Content.Pipeline.FbxImporter.ProcessInformationInNode(KFbxNode* fbxNode, String name, Boolean* partOfMainSkeleton, Boolean* warnIfBoneButNotChild)      &lt;br /&gt;
   at Microsoft.Xna.Framework.Content.Pipeline.FbxImporter.ProcessNode(ValueType parentAbsoluteTransform, NodeContent potentialParent, KFbxNode* fbxNode, Boolean partOfMainSkeleton, Boolean warnIfBoneButNotChild)      &lt;br /&gt;
   at Microsoft.Xna.Framework.Content.Pipeline.FbxImporter.ProcessNode(ValueType parentAbsoluteTransform, NodeContent potentialParent, KFbxNode* fbxNode, Boolean partOfMainSkeleton, Boolean warnIfBoneButNotChild)      &lt;br /&gt;
   at Microsoft.Xna.Framework.Content.Pipeline.FbxImporter.Import(String filename, ContentImporterContext context)      &lt;br /&gt;
   at Microsoft.Xna.Framework.Content.Pipeline.ContentImporter`1.Microsoft.Xna.Framework.Content.Pipeline.IContentImporter.Import(String filename, ContentImporterContext context)      &lt;br /&gt;
   //additional calls here …&lt;/em&gt;    &lt;br /&gt;
 &lt;/p&gt;
&lt;p&gt;My desktop PC have 8Gb RAM, and Visual Studio’s process devenv.exe use under 2Gb of it while build process (about 3.5-4Gb of RAM is always free). It’s obvious, that VS can’t address more than 2Gb of RAM, and when that limit is over, build process is fail.&lt;/p&gt;
&lt;p&gt;OS on my PC is Win x64,  so I “charge” devenv.exe by using &lt;strong&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/203797te.aspx"&gt;editbin.exe&lt;/a&gt;&lt;/strong&gt; utility – in the VS Command prompt I run following:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;editbin "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe" /LARGEADDRESSAWARE&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This command edits the image to indicate that the application can handle addresses larger than 2 gigabytes.&lt;/p&gt;
&lt;p&gt;After that FBX file successfully built! Of course, you must put proper path to devenv.exe, depend on your installation path. If you are on Win x86, you need to do additional action – &lt;a href="http://blogs.msdn.com/b/calvin_hsia/archive/2010/09/27/10068359.aspx"&gt;more info here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;em&gt;P.S.: although now you can build a bigger files, than usual, keep in mind, that &lt;/em&gt;&lt;a href="http://blogs.msdn.com/b/shawnhar/archive/2010/03/12/reach-vs-hidef.aspx"&gt;&lt;em&gt;XNA have some restrictions&lt;/em&gt;&lt;/a&gt;&lt;em&gt; on vertex buffer size etc., depend on your current XNA project profile (Reach or HiDef). And if your model’s vertexbuffer size more than 64Mb (with Reach profile), that model can’t be built and raise an error.&lt;/em&gt;&lt;/p&gt; &lt;img src="http://geekswithblogs.net/vitus/aggbug/145924.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Vitus</dc:creator>
            <guid>http://geekswithblogs.net/vitus/archive/2011/06/20/workaround-build-fbx-in-xna-raise-outofmemoryexception.aspx</guid>
            <pubDate>Mon, 20 Jun 2011 02:53:45 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/vitus/comments/145924.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/vitus/archive/2011/06/20/workaround-build-fbx-in-xna-raise-outofmemoryexception.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/vitus/comments/commentRss/145924.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Workaround: XNA 4 importing only part of 3d model from FBX</title>
            <category>XNA</category>
            <category>FBX</category>
            <category>Autodesk</category>
            <category>FBX Converter</category>
            <link>http://geekswithblogs.net/vitus/archive/2011/06/19/workaround-xna-4-importing-only-part-of-3d-model-from.aspx</link>
            <description>&lt;p&gt;Recently I found a problem with importing 3D models from FBX files: it sometimes imported partly. That is when you draw a 3D model, loaded from FBX file, processed by content pipeline, you got only part of meshes. “Sometimes” means that you got this error only for some files. Results of my research below.&lt;/p&gt;
&lt;p&gt;For example, I have 10Mb binary FBX file with a model, looks like:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://habreffect.ru/files/23d/542fa7f67/source_model.png" /&gt;&lt;/p&gt;
&lt;p&gt;And when I load it, result Model instance contains only part of meshes and looks like:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://habreffect.ru/files/28a/6e61c0215/Result_view.png" /&gt;&lt;/p&gt;
&lt;p&gt;Because models from other files imported normally, I think that it’s a “bad format” file.&lt;/p&gt;
&lt;p&gt;When you add FBX file to your XNA Content project and build it, imported file processing by XNA Fbx Importer &amp;amp; Processor. On &lt;a href="http://msdn.microsoft.com/en-us/library/bb447762%28v=XNAGameStudio.40%29.aspx"&gt;MSDN&lt;/a&gt; I found that FbxImporter designed to work with 2006.11 version of FBX format. My file is FBX 2012 format.&lt;/p&gt;
&lt;p&gt;Ok, I need to convert it to 2006 format. It can be done by using Autodesk &lt;a href="http://usa.autodesk.com/adsk/servlet/pc/item?id=10775855&amp;amp;siteID=123112"&gt;FBX Converter 2012.1&lt;/a&gt;. I tried to convert it to other versions of FBX formats, but without success.&lt;/p&gt;
&lt;p&gt;And I also tried to import my FBX file to 3D MAX, and it imported correctly. Then I export model using 3D MAX, and it generate me other FBX, which I add to my XNA project. After that I got full model, that rendered well!&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;So, internal data structure of FBX file is more important for right XNA import, than it version!&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Unfortunately, Autodesk FBX is not an open file format. If you want to work with FBX, you should use Autodesk FBX SDK. This way you can manually read content of FBX file, and use it everyway.&lt;/p&gt;
&lt;p&gt;Then I tried to convert my source FBX file to DAE Collada, and result DAE file back to FBX, using FBX Converter (FBX –&amp;gt; DAE –&amp;gt; FBX). The result FBX file can be imported normally.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;font size="2"&gt;Conclusion:&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
    &lt;li&gt;&lt;em&gt;XNA FbxImporter correct work doesn't depend on version (2006, 2011, etc) and form (binary, ascii) of FBX file. Internal FBX data structure much more important. &lt;/em&gt;&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;To make FBX "readable" for XNA Importer you can use double conversion like FBX -&amp;gt; Collada -&amp;gt; FBX &lt;/em&gt;&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;You also can use FBX SDK to manually load data from FBX&lt;/em&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;P.S. Autodesk FBX Converter 2012 is more, than simple converter. It provide you tools like:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;FBX Explorer, which show you structure of FBX file;&lt;/li&gt;
    &lt;li&gt;FBX Viewer, which render content of FBX and provide basic intercation like model move and zoom;&lt;/li&gt;
    &lt;li&gt;FBX Take Manager, which allow to work with embedded animations&lt;/li&gt;
&lt;/ul&gt; &lt;img src="http://geekswithblogs.net/vitus/aggbug/145907.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Vitus</dc:creator>
            <guid>http://geekswithblogs.net/vitus/archive/2011/06/19/workaround-xna-4-importing-only-part-of-3d-model-from.aspx</guid>
            <pubDate>Sun, 19 Jun 2011 00:01:42 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/vitus/comments/145907.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/vitus/archive/2011/06/19/workaround-xna-4-importing-only-part-of-3d-model-from.aspx#feedback</comments>
            <slash:comments>3</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/vitus/comments/commentRss/145907.aspx</wfw:commentRss>
        </item>
        <item>
            <title>HSLS syntax highlight in Visual Studio 2010</title>
            <category>Visual Studio</category>
            <category>HLSL</category>
            <category>shader</category>
            <category>hint</category>
            <link>http://geekswithblogs.net/vitus/archive/2011/05/13/hsls-syntax-highlight-in-visual-studio-2010.aspx</link>
            <description>&lt;p&gt;Visual Studio 2010 is not support built-in syntax highlight for HLSL, and I found great soultion – &lt;a href="http://nshader.codeplex.com/"&gt;NShader – HLSL\ GLSL \ CG - Shader Syntax Highlighter add-in for Visual Studio&lt;/a&gt;. And now editor window with loaded *.fx file looks like following:&lt;/p&gt;
&lt;p&gt;&lt;img width="385" height="246" title="image" alt="image" border="0" style="border: 0px currentColor; padding-top: 0px; padding-right: 0px; padding-left: 0px; display: inline; background-image: none;" src="http://geekswithblogs.net/images/geekswithblogs_net/vitus/Windows-Live-Writer/Shader-language-color_FCEE/image_5.png" /&gt;&lt;/p&gt;
&lt;p&gt;NShader support VS 2008 and 2010, and it’s free.&lt;/p&gt;
&lt;p&gt;Another way to get syntax highlight is to set VS for opening *.fx in &lt;a href="http://notepad-plus-plus.org/"&gt;Notepad++&lt;/a&gt; (with one of HLSL language definitions, it hasn’t built-in support).&lt;/p&gt;
&lt;p&gt;I like to stay inside Visual Studio, so I prefer NShader :)&lt;/p&gt; &lt;img src="http://geekswithblogs.net/vitus/aggbug/145323.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Vitus</dc:creator>
            <guid>http://geekswithblogs.net/vitus/archive/2011/05/13/hsls-syntax-highlight-in-visual-studio-2010.aspx</guid>
            <pubDate>Fri, 13 May 2011 06:26:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/vitus/comments/145323.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/vitus/archive/2011/05/13/hsls-syntax-highlight-in-visual-studio-2010.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/vitus/comments/commentRss/145323.aspx</wfw:commentRss>
        </item>
        <item>
            <title>.NET 4: &amp;ldquo;Slim&amp;rdquo;-style performance boost!</title>
            <category>Parallel Extension</category>
            <category>.NET</category>
            <category>concurrency</category>
            <link>http://geekswithblogs.net/vitus/archive/2010/04/15/net-4-slim-style-performance-boost.aspx</link>
            <description>&lt;p&gt;RTM version of .NET 4 and Visual Studio 2010 is &lt;a href="http://www.microsoft.com/visualstudio/ru-ru/download"&gt;available&lt;/a&gt;, and now we can do some test with it.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://msdn.microsoft.com/ru-ru/concurrency/ee851578%28en-us%29.aspx"&gt;Parallel Extensions&lt;/a&gt; is one of the most valuable part of .NET 4.0. It’s a set of good tools for easily consuming multicore hardware power. And it also contains some “upgraded” sync primitives – Slim-version.&lt;/p&gt;
&lt;p&gt;For example, it include updated variant of widely known &lt;a href="http://msdn.microsoft.com/en-us/library/system.threading.manualresetevent.aspx"&gt;ManualResetEvent&lt;/a&gt;. For people, who don’t know about it: you can sync concurrency execution of some pieces of code with this sync primitive. Instance of ManualResetEvent can be in 2 states: signaled and non-signaled. Transition between it possible by Set() and Reset() methods call. Some shortly explanation:&lt;/p&gt;
&lt;table cellspacing="0" cellpadding="2" border="0" width="400"&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td width="152" valign="top"&gt;
            &lt;p align="center"&gt;&lt;strong&gt;Thread 1&lt;/strong&gt;&lt;/p&gt;
            &lt;/td&gt;
            &lt;td width="144" valign="top"&gt;
            &lt;p align="center"&gt;&lt;strong&gt;Thread&lt;/strong&gt;&lt;strong&gt; 2&lt;/strong&gt;&lt;/p&gt;
            &lt;/td&gt;
            &lt;td width="102" valign="top"&gt;
            &lt;p align="center"&gt;&lt;strong&gt;Time&lt;/strong&gt;&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td width="152" valign="top"&gt;mre.Reset();          &lt;br /&gt;
            mre.WaitOne();&lt;/td&gt;
            &lt;td width="144" valign="top"&gt;//code execution&lt;/td&gt;
            &lt;td width="102" valign="top"&gt;0&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td width="152" valign="top"&gt;//wating&lt;/td&gt;
            &lt;td width="144" valign="top"&gt;//code execution&lt;/td&gt;
            &lt;td width="102" valign="top"&gt;1&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td width="152" valign="top"&gt;//wating&lt;/td&gt;
            &lt;td width="144" valign="top"&gt;//code execution&lt;/td&gt;
            &lt;td width="102" valign="top"&gt;2&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td width="152" valign="top"&gt;//wating&lt;/td&gt;
            &lt;td width="144" valign="top"&gt;//code execution&lt;/td&gt;
            &lt;td width="102" valign="top"&gt;3&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td width="152" valign="top"&gt;//wating&lt;/td&gt;
            &lt;td width="144" valign="top"&gt;mre.Set();&lt;/td&gt;
            &lt;td width="131" valign="top"&gt;4&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td width="152" valign="top"&gt;//code execution&lt;/td&gt;
            &lt;td width="144" valign="top"&gt;//…&lt;/td&gt;
            &lt;td width="131" valign="top"&gt;5&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Upgraded version of this primitive is &lt;a href="http://msdn.microsoft.com/en-us/library/system.threading.manualreseteventslim%28VS.100%29.aspx"&gt;ManualResetEventSlim&lt;/a&gt;. The idea in decreasing performance cost in case, when only 1 thread use it. Main concept in the “hybrid sync schema”, which can be done as following:&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;internal&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;sealed&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; SimpleHybridLock : IDisposable&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
{&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
    &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; Int32 m_waiters = 0;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
    &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; AutoResetEvent m_waiterLock = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; AutoResetEvent(&lt;span style="color: rgb(0, 0, 255);"&gt;false&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
 &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
    &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Enter()&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
    {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
        &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (Interlocked.Increment(&lt;span style="color: rgb(0, 0, 255);"&gt;ref&lt;/span&gt; m_waiters) == 1)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
            &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
        m_waiterLock.WaitOne();&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
    }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
 &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
    &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Leave()&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
    {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
        &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (Interlocked.Decrement(&lt;span style="color: rgb(0, 0, 255);"&gt;ref&lt;/span&gt; m_waiters) == 0)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
            &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
        m_waiterLock.Set();&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
    }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
 &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
    &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Dispose()&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
    {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
        m_waiterLock.Dispose();&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
    }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;It’s a sample from Jeffry Richter’s book &lt;a href="http://www.amazon.com/CLR-via-Dev-Pro-Jeffrey-Richter/dp/0735627045/ref=sr_1_1?ie=UTF8&amp;amp;s=books&amp;amp;qid=1271301676&amp;amp;sr=1-1"&gt;“CLR via C#”, 3rd edition&lt;/a&gt;. Primitive SimpleHybridLock have two public methods: Enter() and Leave(). You can put your concurrency-critical code between calls of these methods, and it would executed in only one thread at the moment. Code is really simple: first thread, called Enter(), increase counter. Second thread also increase counter, and suspend while m_waiterLock is not signaled. So, if we don’t have concurrent access to our lock, “heavy” methods WaitOne() and Set() will not called. It’s can give some performance bonus.&lt;/p&gt;
&lt;p&gt;ManualResetEvent use the similar idea. Of course, it have more “smart” technics inside, like a checking of recursive calls, and so on. I want to know a real difference between classic ManualResetEvent realization, and new –Slim. I wrote a simple “benchmark”:&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; Program&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
{&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
    &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Main(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;[] args)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
    {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
        ManualResetEventSlim mres = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; ManualResetEventSlim(&lt;span style="color: rgb(0, 0, 255);"&gt;false&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
        ManualResetEventSlim mres2 = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; ManualResetEventSlim(&lt;span style="color: rgb(0, 0, 255);"&gt;false&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
 &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
        ManualResetEvent mre = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; ManualResetEvent(&lt;span style="color: rgb(0, 0, 255);"&gt;false&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
 &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
        &lt;span style="color: rgb(0, 0, 255);"&gt;long&lt;/span&gt; total = 0;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
        &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; COUNT = 50;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
 &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
        &lt;span style="color: rgb(0, 0, 255);"&gt;for&lt;/span&gt; (&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; i = 0; i &amp;lt; COUNT; i++)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
        {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
            mres2.Reset();&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
            Stopwatch sw = Stopwatch.StartNew();&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
 &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
            ThreadPool.QueueUserWorkItem((obj) =&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
            {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
                &lt;span style="color: rgb(0, 128, 0);"&gt;//Method(mres, true);&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
                Method2(mre, &lt;span style="color: rgb(0, 0, 255);"&gt;true&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
                mres2.Set();&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
            });&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
            &lt;span style="color: rgb(0, 128, 0);"&gt;//Method(mres, false);&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
            Method2(mre, &lt;span style="color: rgb(0, 0, 255);"&gt;false&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
 &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
            mres2.Wait();&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
            sw.Stop();&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
 &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
            Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;"Pass {0}: {1} ms"&lt;/span&gt;, i, sw.ElapsedMilliseconds);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
            total += sw.ElapsedMilliseconds;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
        }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
 &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
        Console.WriteLine();&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
        Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;"==============================="&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
        Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;"Done in average="&lt;/span&gt; + total / (&lt;span style="color: rgb(0, 0, 255);"&gt;double&lt;/span&gt;)COUNT);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
        Console.ReadLine();&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
    }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
 &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
    &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Method(ManualResetEventSlim mre, &lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
    {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
        &lt;span style="color: rgb(0, 0, 255);"&gt;for&lt;/span&gt; (&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; i = 0; i &amp;lt; 9000000; i++)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
        {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
            &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (&lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
            {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
                mre.Set();&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
            }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
            &lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
            {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
                mre.Reset();&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
            }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
        }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
    }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
 &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
    &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Method2(ManualResetEvent mre, &lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
    {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
        &lt;span style="color: rgb(0, 0, 255);"&gt;for&lt;/span&gt; (&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; i = 0; i &amp;lt; 9000000; i++)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
        {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
            &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (&lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
            {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
                mre.Set();&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
            }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
            &lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
            {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
                mre.Reset();&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
            }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
        }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
    }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;"&gt;
}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;I use 2 concurrent thread (the main thread and one from thread pool) for setting and resetting ManualResetEvents, and try to run test COUNT times, and calculate average execution time. Here is the results (I get it on my dual core notebook with T7250 CPU and Windows 7 x64):&lt;/p&gt;
&lt;table cellspacing="0" cellpadding="2" border="0" width="402"&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td width="200" valign="top"&gt;
            &lt;p align="center"&gt;ManualResetEvent&lt;/p&gt;
            &lt;/td&gt;
            &lt;td width="200" valign="top"&gt;
            &lt;p align="center"&gt;ManualResetEvent&lt;strong&gt;Slim&lt;/strong&gt;&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td width="200" valign="top"&gt;&lt;img height="341" border="0" width="313" src="http://geekswithblogs.net/images/geekswithblogs_net/vitus/WindowsLiveWriter/1491f37d49.NET4Slimstyleperformanceboost_AD31/image9_3.png" alt="image9" title="image9" style="border-width: 0px; display: inline;" /&gt;&lt;/td&gt;
            &lt;td width="200" valign="top"&gt;&lt;img height="337" border="0" width="279" src="http://geekswithblogs.net/images/geekswithblogs_net/vitus/WindowsLiveWriter/1491f37d49.NET4Slimstyleperformanceboost_AD31/image4_3.png" alt="image4" title="image4" style="border-width: 0px; display: inline;" /&gt;&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Difference is obvious and serious – in 10 times!&lt;/p&gt;
&lt;p&gt;So, I think preferable way is using ManualResetEventSlim, because not always on calling Set() and Reset() will be called “heavy” methods for working with Windows kernel-mode objects. It’s a small and nice improvement! ;)&lt;/p&gt; &lt;img src="http://geekswithblogs.net/vitus/aggbug/139276.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Vitus</dc:creator>
            <guid>http://geekswithblogs.net/vitus/archive/2010/04/15/net-4-slim-style-performance-boost.aspx</guid>
            <pubDate>Wed, 14 Apr 2010 20:28:24 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/vitus/comments/139276.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/vitus/archive/2010/04/15/net-4-slim-style-performance-boost.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/vitus/comments/commentRss/139276.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Workaround: VS2008 SP1 is not responding when edit view in the ASP.NET MVC project</title>
            <category>Visual Studio</category>
            <category>ASP.NET MVC</category>
            <category>workaround</category>
            <link>http://geekswithblogs.net/vitus/archive/2009/11/23/workaround-vs2008-sp1-is-not-responding-when-edit-view-in-again.aspx</link>
            <description>&lt;p&gt;Today I saw interesting behavior in VS2008: when you try to edit any View in the ASP.NET MVC project, main window of VS is not responding. Effect is like a some “invisible” modal dialog window is shown, and you can’t close it by Space or Enter. When you try to click in any part of VS’s window, you get an error beep. &lt;/p&gt;  &lt;p&gt;I tried to unload all of add-ins, uninstall Resharper, reset VS settings – it’s useless. Solution is &lt;a href="http://forums.asp.net/t/1398559.aspx"&gt;here&lt;/a&gt; (big thank you, guys :)): uninstall “Microsoft Visual Studio Web Authoring Component” through “Programs and Features”, and install it again from the “\WCU\WebDesignerCore\WebDesignerCore.EXE” folder inside the VS2008 installation media.&lt;/p&gt;  &lt;p&gt;After that VS is working normally!&lt;/p&gt; &lt;img src="http://geekswithblogs.net/vitus/aggbug/136490.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Vitus</dc:creator>
            <guid>http://geekswithblogs.net/vitus/archive/2009/11/23/workaround-vs2008-sp1-is-not-responding-when-edit-view-in-again.aspx</guid>
            <pubDate>Mon, 23 Nov 2009 12:59:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/vitus/comments/136490.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/vitus/archive/2009/11/23/workaround-vs2008-sp1-is-not-responding-when-edit-view-in-again.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/vitus/comments/commentRss/136490.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Client part of WCF REST Starter Kit</title>
            <category>WCF</category>
            <category>REST</category>
            <category>.NET</category>
            <link>http://geekswithblogs.net/vitus/archive/2009/10/28/client-part-of-wcf-rest-starter-kit.aspx</link>
            <description>&lt;p&gt;WCF REST Starter Kit Preview 2 contains not only tools for creating REST services. It include rich set of client tools, that allow to do HTTP-requests and process service response in more convenient way. I create small overview of it basic features.&lt;/p&gt;
&lt;p&gt;We’ll create a simple WPF desktop client for Yahoo Shopping Web Services. Our client sill search products by the keyword. Details of Search API is available here, but information about GET-request format and service URI is enough. For example, if we want to search for “digital camera”, we shall use following URL: &lt;a href="http://shopping.yahooapis.com/ShoppingService/v3/productSearch?appid=YahooDemo&amp;amp;query=digital+camera&amp;amp;show_numratings=1"&gt;http://shopping.yahooapis.com/ShoppingService/v3/productSearch?appid=YahooDemo&amp;amp;query=digital+camera&amp;amp;show_numratings=1&lt;/a&gt;. Parameter &lt;strong&gt;appId &lt;/strong&gt;is a Yahoo id of your app. We can you demo id for our purposes and use “YahooDemo”. Keyword is passed through &lt;strong&gt;query &lt;/strong&gt;parameter, and &lt;strong&gt;show_numratings&lt;/strong&gt;=1 allow us to receive user rating of each product in the results. So, we need to do some GET-request and process server response.&lt;/p&gt;
&lt;p&gt;User of our application enter search keywords to the TextBox, and we use Microsoft.Http.HttpQueryString class for making the URL:&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; keyword = searchString.Text.ToLower().Trim().Replace(&lt;span style="color: rgb(0, 96, 128);"&gt;' '&lt;/span&gt;, &lt;span style="color: rgb(0, 96, 128);"&gt;'+'&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;HttpQueryString query = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpQueryString();&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;query.Add(&lt;span style="color: rgb(0, 96, 128);"&gt;"appid"&lt;/span&gt;, &lt;span style="color: rgb(0, 96, 128);"&gt;"YahooDemo"&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;query.Add(&lt;span style="color: rgb(0, 96, 128);"&gt;"query"&lt;/span&gt;, keyword);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;query.Add(&lt;span style="color: rgb(0, 96, 128);"&gt;"show_numratings"&lt;/span&gt;, &lt;span style="color: rgb(0, 96, 128);"&gt;"1"&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;We simply add “parameter-value” pairs to the list, and call of MakeQueryString() method allow us to get the Uri:&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; uri = query.MakeQueryString(&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Uri(&lt;span style="color: rgb(0, 96, 128);"&gt;"http://localhost/script.php"&lt;/span&gt;)).AbsoluteUri;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;In this example we receive following: &lt;em&gt;http://localhost/script.php?appid=YahooDemo&amp;amp;query=notebook&amp;amp;show_numratings=1&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;We’ll use HttpClient class for sending request to the server. It allow us to execute wide range of HTTP-requests, it have multiple settings, for example HTTP headers, timeout of sending/receiving and other, it support sync and async requests, etc. And I think, it has more convenient API, then classic HttpWebRequest. And WebClient class don’t have some “must have” features, such as timeout settings (for example, if you try to POST large amount of data to the server through the poor channel, you often fail with timeout). Let’s take a look at HttpClient class:&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;HttpClient client = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpClient(&lt;span style="color: rgb(0, 96, 128);"&gt;@"http://shopping.yahooapis.com/ShoppingService/V3/"&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;client.DefaultHeaders.UserAgent.AddString(&lt;span style="color: rgb(0, 96, 128);"&gt;@"Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 4.0.20506)"&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;HttpResponseMessage response = client.Get(&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Uri(&lt;span style="color: rgb(0, 96, 128);"&gt;"productSearch"&lt;/span&gt;, UriKind.Relative), query);&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;With these 3 lines of code we perform sync GET-request to the server, and receive the response. We create instance of HttpClient with the base part of URL in the constructor. Then we add UserAgent header, because else server is not process the request normally. After that we make a request by calling Get() extension method. We can call REST service in other way:&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;HttpResponseMessage response = client.Send(HttpMethod.GET,query.MakeQueryString(&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Uri(&lt;span style="color: rgb(0, 96, 128);"&gt;"productSearch"&lt;/span&gt;, UriKind.Relative)), HttpContent.CreateEmpty());&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Here is used “universal” Send() method, where type of HTTP-method is typed explicitly. Of course, Get(), Post() and etc. is calling Send() internally, but usage of them is making code more “human-readable”. You can check state of response:&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;response.EnsureStatusIsSuccessful();&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;So, if HTTP-response code is not 2xx, then we get an exception. The value of response code is available through StatusCode property.&lt;/p&gt;
&lt;p&gt;Ok, we get an XML response. But we need more not an XML but a collection of entities. You can create entity classes manually. Or you can route this task to the “Paste XML as Type” add-in for VS 2008. This add-in is included in the WCF REST Starter Kit. It have very simple UI – just a single item in the Edit menu of VS:&lt;/p&gt;
&lt;p&gt;&lt;img height="250" border="0" width="269" src="http://geekswithblogs.net/images/geekswithblogs_net/vitus/WindowsLiveWriter/ClientpartofWCFRESTStarterKit_908C/image8_3.png" alt="image8" title="image8" style="border: 0px none ; display: block; float: none; margin-left: auto; margin-right: auto;" /&gt;&lt;/p&gt;
&lt;p&gt;You can copy XML response of the server and use this add-in. As a result you’ll get a set of generated entity classes, using it you can parse server response and get an instances. One disadvantage – sometime names of the types and properties is not useful and you need to change it manually.&lt;/p&gt;
&lt;p&gt;So, you can get collection of the elements as following:&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;ProductSearch results = response.Content.ReadAsXmlSerializable&amp;lt;ProductSearch&amp;gt;();&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;That’s all. We only need to data-bind result of request and or client is ready:&lt;/p&gt;
&lt;p&gt;&lt;img height="328" border="0" width="379" src="http://geekswithblogs.net/images/geekswithblogs_net/vitus/WindowsLiveWriter/ClientpartofWCFRESTStarterKit_908C/image16_3.png" alt="image16" title="image16" style="border: 0px none ; display: block; float: none; margin-left: auto; margin-right: auto;" /&gt;&lt;/p&gt;
&lt;p&gt;We can receive server response in other ways:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;as &lt;strong&gt;byte[]&lt;/strong&gt; by calling ReadAsByteArray(); &lt;/li&gt;
    &lt;li&gt;as &lt;strong&gt;string&lt;/strong&gt; by calling ReadAsString(); &lt;/li&gt;
    &lt;li&gt;as &lt;strong&gt;stream&lt;/strong&gt; by calling ReadAsStream(); &lt;/li&gt;
    &lt;li&gt;as &lt;strong&gt;XElement&lt;/strong&gt; for processing with XLINQ by calling ReadAsXElement(); &lt;/li&gt;
    &lt;li&gt;as &lt;strong&gt;XmlReader&lt;/strong&gt; by calling ReadAsXmlReader(); &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Ok, but that about services, which use JSON or RSS/Atom format? Starter Kit’s client part have appropriate extension-methods for HttpContent: ReadAsJsonDataContract&amp;lt;T&amp;gt;() and ReadAsSyndicationFeed().&lt;/p&gt;
&lt;p&gt;With the source codes of WCF REST Starter Kit Preview 2 you can get an interesting WPF application, that allow to perform different types of HTTP-requests and analyze the response. You can see other “real world” examples of usage client parts on this sample app. And you must know, that I describe only basic features of client part of Starter Kit. It contains interesting and useful advanced possibilities.&lt;/p&gt; &lt;img src="http://geekswithblogs.net/vitus/aggbug/135773.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Vitus</dc:creator>
            <guid>http://geekswithblogs.net/vitus/archive/2009/10/28/client-part-of-wcf-rest-starter-kit.aspx</guid>
            <pubDate>Wed, 28 Oct 2009 08:05:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/vitus/comments/135773.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/vitus/archive/2009/10/28/client-part-of-wcf-rest-starter-kit.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/vitus/comments/commentRss/135773.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Thread-safe data structures .NET 4.0 (part 2)</title>
            <category>Parallel Extension</category>
            <category>.NET</category>
            <category>data</category>
            <category>concurrency</category>
            <link>http://geekswithblogs.net/vitus/archive/2009/10/25/thread-safe-data-structures-.net-4.0-part-2.aspx</link>
            <description>&lt;p&gt;Today I tell you about BlockingCollection&amp;lt;T&amp;gt;. It’s more complex and more interesting data storage.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;BlockingCollection&amp;lt;T&amp;gt;&lt;/strong&gt; is a thread-safe data structure, which is called “blocking”, because it based on following principles:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;if the collection is empty, and some code try to take an element, the thread, that executes this code, is blocked while any at least one element is not added;&lt;/li&gt;
    &lt;li&gt;if the collection already contains maximum elements, the thread, attempting to add new element, will be blocked until free space for the element is not available.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Of course, it’s not a full description of the collection’s possibilities.&lt;/p&gt;
&lt;p&gt;Let’s start to introduce with BlockingCollection&amp;lt;T&amp;gt;. It has few methods for manipulating data:&lt;/p&gt;
&lt;table cellspacing="0" cellpadding="0" border="1" width="640"&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td valign="top" width="102"&gt;
            &lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;
            &lt;/td&gt;
            &lt;td valign="top" width="268"&gt;
            &lt;p align="center"&gt;&lt;strong&gt;Blocking methods&lt;/strong&gt;&lt;/p&gt;
            &lt;/td&gt;
            &lt;td valign="top" width="268"&gt;
            &lt;p align="center"&gt;&lt;strong&gt;non-Blocking methods&lt;/strong&gt;&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td valign="top" width="102"&gt;
            &lt;p align="center"&gt;&lt;strong&gt;Add&lt;/strong&gt;&lt;/p&gt;
            &lt;/td&gt;
            &lt;td valign="top" width="268"&gt;Add(T);          &lt;br /&gt;
            Add(T, CancellationToken); &lt;/td&gt;
            &lt;td valign="top" width="268"&gt;TryAdd(T)          &lt;br /&gt;
            TryAdd(T, Int32)           &lt;br /&gt;
            TryAdd(T, TimeSpan)           &lt;br /&gt;
            TryAdd(T, Int32, CancellationToken) &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td valign="top" width="102"&gt;
            &lt;p align="center"&gt;&lt;strong&gt;Take&lt;/strong&gt;&lt;/p&gt;
            &lt;/td&gt;
            &lt;td valign="top" width="268"&gt;Take()          &lt;br /&gt;
            Take(CancellationToken) &lt;/td&gt;
            &lt;td valign="top" width="268"&gt;TryTake(out T)          &lt;br /&gt;
            TryTake(out T, Int32)           &lt;br /&gt;
            TryTake(out T, TimeSpan)           &lt;br /&gt;
            TryTake(out T, Int32, CancellationToken) &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;How you can see, we have both types of methods – blocking and non-blocking (starts with “Try” prefix). Try*-method return true on success of adding or taking an element, else – false. Both types have overloads with cancellation token, which allow to cancel method async.&lt;/p&gt;
&lt;p&gt;BlockingCollection&amp;lt;T&amp;gt; have mechanism of completion. Collection is completed, if we will not add any data in future. After completion all attempts to add some data will result in generation of InvalidOperationException. If we try to take an element from empty completed collection, we also have an exception. When we create a collection, it is not completed, and completion is doing by calling CompeteAdding() method. So, we must complete the collection explicitly. How you can use the completion mechanism? You can sync producer and consumer, i.e. parts of code, adding and taking data from the collection. Producer may notice, that new data will not be added by marking the collection as completed. So, consumer will not be wait for new elements.&lt;/p&gt;
&lt;p&gt;Ok, here is some code, that demonstrate how to work with BlockingCollection&amp;lt;T&amp;gt;. First of all we instantiate the collection, and set max elements count. However, we can use constructor overload without parameters, that allow collection to grow “infinite”:&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;// create the collection&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;BlockingCollection&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;&amp;gt; collection = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; BlockingCollection&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;&amp;gt;(10);&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Next we will add some elements and print some properties of collection (I’ll talk about it later):&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;collection.Add(200);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;collection.Add(300);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;collection.Add(400);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;collection.Add(500);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;"Count: "&lt;/span&gt; + collection.Count);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;"BoundedCapacity: "&lt;/span&gt; + collection.BoundedCapacity);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;"IsCompleted: "&lt;/span&gt; + collection.IsCompleted);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;"IsAddingCompleted: "&lt;/span&gt; + collection.IsAddingCompleted);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;Console.WriteLine();&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;After that we start the timer. At the callback delegate more elements will be added, and collection is mark as completed:&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;Timer timer = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Timer(&lt;span style="color: rgb(0, 0, 255);"&gt;delegate&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    Console.ForegroundColor = ConsoleColor.Red;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    Console.WriteLine(DateTime.Now.ToLongTimeString() + &lt;span style="color: rgb(0, 96, 128);"&gt;" Adding "&lt;/span&gt; + &lt;span style="color: rgb(0, 96, 128);"&gt;" 600"&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    collection.Add(600);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    Thread.SpinWait(300000000);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    Console.ForegroundColor = ConsoleColor.Red;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    Console.WriteLine(DateTime.Now.ToLongTimeString() + &lt;span style="color: rgb(0, 96, 128);"&gt;" Adding "&lt;/span&gt; + &lt;span style="color: rgb(0, 96, 128);"&gt;" 700"&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    collection.Add(700);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    collection.CompleteAdding();&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;},&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;  &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;, 3000, Timeout.Infinite);&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Timer callback will be executed in other thread, than the Main() method. It allow us to model concurrent access to the collection. Then we start taking elements from collection (I use different font colors in different threads):&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;foreach&lt;/span&gt; (var item &lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt; collection.GetConsumingEnumerable())&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    Console.ForegroundColor = ConsoleColor.Gray;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    Console.WriteLine(DateTime.Now.ToLongTimeString() + &lt;span style="color: rgb(0, 96, 128);"&gt;" Taking "&lt;/span&gt; + item);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Here is the result of work:&lt;/p&gt;
&lt;p&gt; &lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/vitus/WindowsLiveWriter/Threadsafedatastructures.NET4.0part2_E949/image_7.png"&gt;&lt;img height="268" border="0" width="210" src="http://geekswithblogs.net/images/geekswithblogs_net/vitus/WindowsLiveWriter/Threadsafedatastructures.NET4.0part2_E949/image_thumb_2.png" alt="image" title="image" style="border: 0px none ; display: inline;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Some words on how this example is work. We create a collection, and add 4 element to it. Next we start the timer, so we have 2 threads:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;the main thread, where method Main() is executing and taking elements from the collection;&lt;/li&gt;
    &lt;li&gt;the timer thread, where timer callback is executing and adding elements;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;On the screenshot you can see that first 4 elements took in time less than 1 second. After that main thread is blocked and waiting for new elements. Timer starts with 3 seconds delay, you can see it: element 500 was took in 40 sec. and element 600 was added in 43 sec. In the same 43 sec. main thread is unblocked and took newly added element 600. Next, the timer thread is executing SpinWait(), after that it add element 700 and complete the collection by calling &lt;em&gt;collection.CompleteAdding()&lt;/em&gt;. And the main thread is consuming this element and unblock, because the collection is completed and all elements are processed. If we comment CompleteAdding() call, the main thread will be blocked forever, because timer callback is returned and nobody mark collection as completed. And the main thread will wait for new elements infinite. So, the completion mechanism allows to avoid such situation and provide good way to solve the issue.&lt;/p&gt;
&lt;p&gt;Some words on collection’s properties. I think, the most interest of them are following:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;strong&gt;IsAddingCompleted&lt;/strong&gt; – returns &lt;strong&gt;true&lt;/strong&gt;, if collection is marked as completed, else &lt;strong&gt;false&lt;/strong&gt;;&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;IsCompleted&lt;/strong&gt; – return &lt;strong&gt;true&lt;/strong&gt;, if collection is completed and empty, else &lt;strong&gt;false&lt;/strong&gt;;&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;BoundedCapacity&lt;/strong&gt; – return collection’s max capacity. Returns –1 in case of growing collection;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Take a look on the screenshot, and you can notice, when collection contains some elements, both of bool properties are false, because collection in not marked as completed. In the last moment it both are true, because all elements is taken and collection is completed.&lt;/p&gt;
&lt;p&gt;Ok, and what about order of elements in the collection? You may notice, that it work as FIFO queue. Is this a predefined behavior? Or we can change it? Answer to these questions give us more careful look at the constructor. It have overload, which contains IProducerConsumerCollection&amp;lt;T&amp;gt; parameter. It implement a storage for the elements. You can use one of the the following collections (described in the &lt;a href="http://geekswithblogs.net/vitus/archive/2009/10/24/thread-safe-data-structures-.net-4.0-part-1.aspx"&gt;part 1&lt;/a&gt;), included in the .NET 4 beta 2:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;ConcurrentStack&amp;lt;T&amp;gt; – thread-safe stack; &lt;/li&gt;
    &lt;li&gt;ConcurrentQueue&amp;lt;T&amp;gt; – thread-safe queue; &lt;/li&gt;
    &lt;li&gt;ConcurrentBag&amp;lt;T&amp;gt; – thread-safe unordered collection, which allows duplicates;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So, BlockingCollection&amp;lt;T&amp;gt; is not a data storage. It implement a logic of access to the storage and mechanism of completion. By default it use ConcurrentQueue&amp;lt;T&amp;gt; as a storage, so you can see FIFO behavior at the samples. We can change it to stack in the constructor:&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;BlockingCollection&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;&amp;gt; collection = &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;                &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; BlockingCollection&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;&amp;gt;(&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; ConcurrentStack&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;&amp;gt;(), 10);&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;and we saw following result:&lt;/p&gt;
&lt;p&gt;&lt;img height="277" border="0" width="211" src="http://geekswithblogs.net/images/geekswithblogs_net/vitus/WindowsLiveWriter/Threadsafedatastructures.NET4.0part2_E949/image_10.png" alt="image" title="image" style="border: 0px none ; display: inline;" /&gt; &lt;/p&gt;
&lt;p&gt;How you can see, order of elements now conform to LIFO. You can realize custom data storage by implementing interface:&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;interface&lt;/span&gt; IProducerConsumerCollection&amp;lt;T&amp;gt; : IEnumerable&amp;lt;T&amp;gt;, ICollection, IEnumerable&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; CopyTo(T[] array, &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; index);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    T[] ToArray();&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt; TryAdd(T item);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt; TryTake(&lt;span style="color: rgb(0, 0, 255);"&gt;out&lt;/span&gt; T item);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;In addition, I want to talk about some interesting static methods of the class BlockingCollection&amp;lt;T&amp;gt;. You can interact with a number of collections simultaneously with the following set of static methods:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;strong&gt;Blocking&lt;/strong&gt;
    &lt;ul&gt;
        &lt;li&gt;int BlockingCollection&amp;lt;T&amp;gt;.AddToAny(BlockingCollection&amp;lt;T&amp;gt;[], T); &lt;/li&gt;
        &lt;li&gt;int BlockingCollection&amp;lt;T&amp;gt;.TakeFromAny(BlockingCollection&amp;lt;T&amp;gt;[], out T); &lt;/li&gt;
    &lt;/ul&gt;
    &lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Non-Blocking&lt;/strong&gt;
    &lt;ul&gt;
        &lt;li&gt;int BlockingCollection&amp;lt;T&amp;gt;.TryAddToAny(BlockingCollection&amp;lt;T&amp;gt;[], T); &lt;/li&gt;
        &lt;li&gt;int BlockingCollection&amp;lt;T&amp;gt;.TryTakeFromAny(BlockingCollection&amp;lt;T&amp;gt;[], out T); &lt;/li&gt;
    &lt;/ul&gt;
    &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;All of these methods take an array of BlockingCollection&amp;lt;T&amp;gt; elements – it’s an array of collections, with it set you’ll interact. They are work as described early Add() and Take() methods, i.e. with blocking logic. Methods return index of the collection, where data has been added or taken, or –1 when the action attempt is fail. More detail description you can read in the &lt;a href="http://msdn.microsoft.com/en-us/library/dd287223%28VS.100%29.aspx"&gt;MSDN&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;And one more interesting fact. In the MSDN you can read, that, for example, TakeFromAny() method return –1, if the taking action is not successful. It’s a blocking method, and when you try to take an element from set of empty non-completed collections, it will wait infinite while an element will be added to any of collection. Or if you complete any of collection, it will throw an ArgumentException. So, you wait, or take an element, or take an exception. And I can’t understood, when TakeFromAny() can return –1. I create a &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/parallelextensions/thread/8848449a-b333-480a-a5bf-ca1b4b971b6f"&gt;topic&lt;/a&gt; on MSDN Parallel Extension forums, and &lt;a href="http://social.msdn.microsoft.com/Profile/en-US/?user=Reed%20Copsey%2c%20Jr.&amp;amp;referrer=http%3a%2f%2fsocial.msdn.microsoft.com%2fForums%2fen-US%2fparallelextensions%2fthread%2f8848449a-b333-480a-a5bf-ca1b4b971b6f&amp;amp;rh=m2YAT0%2fB4zbA7Z%2bsj3HtRsoBetsPpev5EO06Fn%2b4tzo%3d&amp;amp;sp=forums"&gt;Reed Copsey, Jr&lt;/a&gt; accept, that it’s just a documentation issue. He create an appropriate &lt;a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=498890"&gt;item&lt;/a&gt; on the MS Connect. So, you need to be careful when read current MSDN docs about thread-safe collections, because it’s just a preview and may contains an errors.&lt;/p&gt;
&lt;p&gt;In conclusion, other interesting samples of BlockingCollection&amp;lt;T&amp;gt; usage you can find at the &lt;a href="http://code.msdn.microsoft.com/ParExtSamples"&gt;MSDN code gallery&lt;/a&gt;. Now there are only samples for beta 1, but soon refreshed sample pack will be available. I advice you to download Visual &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=dc333ac8-596d-41e3-ba6c-84264e761b81&amp;amp;displaylang=en"&gt;Studio 2010 beta 2&lt;/a&gt;, that is published this week. You can try to work with new features. It contains the latest Parallel Extensions library, that allow you to use full power of modern multi-core hardware. &lt;/p&gt; &lt;img src="http://geekswithblogs.net/vitus/aggbug/135700.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Vitus</dc:creator>
            <guid>http://geekswithblogs.net/vitus/archive/2009/10/25/thread-safe-data-structures-.net-4.0-part-2.aspx</guid>
            <pubDate>Sat, 24 Oct 2009 23:01:12 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/vitus/comments/135700.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/vitus/archive/2009/10/25/thread-safe-data-structures-.net-4.0-part-2.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/vitus/comments/commentRss/135700.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Thread-safe data structures .NET 4.0 (part 1)</title>
            <category>Parallel Extension</category>
            <category>.NET</category>
            <category>data</category>
            <category>concurrency</category>
            <link>http://geekswithblogs.net/vitus/archive/2009/10/24/thread-safe-data-structures-.net-4.0-part-1.aspx</link>
            <description>&lt;p&gt;.NET 4 contains rich set of tools, that allow to create parallelized code more easy. But when we start processing chunk of data in parallel threads, we need to synchronize these threads, and we need some storage for the results of work. Now exist a big number of methods, solving sync issues, and we can realize in code any of them. But MS Parallel Extensions team already do it, and .NET 4 beta versions include set of thread-safe data structures. They implement some popular types of collections, and I want to do an overview of them.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1. &lt;/strong&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd267265(VS.100).aspx"&gt;Queue&lt;/a&gt;&lt;strong&gt;: ConcurrentQueue&amp;lt;T&amp;gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This is a classic FIFO queue, which can be safely accessed from few threads simultaneously. API of this collection is very simple:&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;ConcurrentQueue&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;&amp;gt; queue = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; ConcurrentQueue&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;&amp;gt;();&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;queue.Enqueue(10);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; t;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;Console.WriteLine(queue.TryPeek(&lt;span style="color: rgb(0, 0, 255);"&gt;out&lt;/span&gt; t));&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;Console.WriteLine(queue.TryDequeue(&lt;span style="color: rgb(0, 0, 255);"&gt;out&lt;/span&gt; t));&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
TryPeek() and TryDequeue() methods return an element from queue, but TryPeek() doesn’t remove it from queue. Both methods returns &lt;strong&gt;true&lt;/strong&gt;, if they take an element, else they return &lt;strong&gt;false&lt;/strong&gt;. You can add an element by calling Enqueue() method. Count of elements in the queue you can get by Count property, and if collection contains at least 1 element, property IsEmpty returns true.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;strong&gt;2. &lt;/strong&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd267331%28VS.100%29.aspx"&gt;Stack&lt;/a&gt;&lt;strong&gt;: ConcurrentStack&amp;lt;T&amp;gt;&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;p&gt;This is a simple LIFO stack, that can be used in the concurrent environment. In contrast to queue, you can easily add or take the range of elements:&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;ConcurrentStack&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;&amp;gt; stack = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; ConcurrentStack&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;&amp;gt;();&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;stack.Push(10);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;stack.PushRange(&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;[] { 1, 2, 3, 4, 5 });&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; t;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (stack.TryPop(&lt;span style="color: rgb(0, 0, 255);"&gt;out&lt;/span&gt; t))&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;"Pop: "&lt;/span&gt; + t);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (stack.TryPeek(&lt;span style="color: rgb(0, 0, 255);"&gt;out&lt;/span&gt; t))&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;"Peek: "&lt;/span&gt; + t);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;[] ts = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;[5];&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; count;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; ((count = stack.TryPopRange(ts, 0, 3)) &amp;gt; 0)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;"PopRange"&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;for&lt;/span&gt; (&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; i = 0; i &amp;lt; count; i++)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;        Console.WriteLine(ts[i]);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Here is the result of work of this code:&lt;/p&gt;
&lt;p&gt;&lt;img height="100" border="0" width="86" src="http://geekswithblogs.net/images/geekswithblogs_net/vitus/WindowsLiveWriter/Threadsafedatastructures.NET4.0part1_AA08/image_3.png" alt="image" title="image" style="border-width: 0px; display: inline;" /&gt; &lt;/p&gt;
&lt;p&gt;TryPeek() and TryPop() methods return bool values, and TryPopRange() – count of retrieved elements. You may add range of values by calling PushRange() method.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3. &lt;/strong&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd381779%28VS.100%29.aspx"&gt;Collection&lt;/a&gt;&lt;strong&gt;: ConcurrentBag&amp;lt;T&amp;gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This is an unordered collection of data, which is looks like a set, but it can store duplicate items. It doesn’t guarantee any order of elements. I think, it’s a most simple data structure:&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;ConcurrentBag&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;&amp;gt; bag = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; ConcurrentBag&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;&amp;gt;(&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;[] { 1, 1, 2, 3 });&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;bag.Add(70);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; t;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;bag.TryPeek(&lt;span style="color: rgb(0, 0, 255);"&gt;out&lt;/span&gt; t);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;Console.WriteLine(t);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;bag.Add(110);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;Console.WriteLine();&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;for&lt;/span&gt; (&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; i = 0; i &amp;lt; 3; i++)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    bag.TryTake(&lt;span style="color: rgb(0, 0, 255);"&gt;out&lt;/span&gt; t);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    Console.WriteLine(t);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;This piece of code produce following console output:&lt;/p&gt;
&lt;p&gt;&lt;img height="76" border="0" width="64" src="http://geekswithblogs.net/images/geekswithblogs_net/vitus/WindowsLiveWriter/Threadsafedatastructures.NET4.0part1_AA08/image_6.png" alt="image" title="image" style="border-width: 0px; display: inline;" /&gt; &lt;/p&gt;
&lt;p&gt;Looking at screenshot, you can notice, that elements retrieved in LIFO. I repeat: no any orders is guaranteed.&lt;/p&gt;
&lt;p&gt;Take a look at the constructor of bag – you can set initial range of elements, and constructors of queue and stack have appropriate overloads too.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;4. &lt;/strong&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd287191%28VS.100%29.aspx"&gt;Dictionary&lt;/a&gt;&lt;strong&gt;: ConcurrentDictionary&amp;lt;TKey, TValue&amp;gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;It’s just a variant of Dictionary&amp;lt;TKey, TValue&amp;gt;, which can be accessed concurrently. API for this collection has some thread-safe specific features:&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;ConcurrentDictionary&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;, &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;&amp;gt; dict = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; ConcurrentDictionary&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;, &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;&amp;gt;();&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;dict.TryAdd(&lt;span style="color: rgb(0, 96, 128);"&gt;"name"&lt;/span&gt;, &lt;span style="color: rgb(0, 96, 128);"&gt;"OFC340"&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;dict.TryAdd(&lt;span style="color: rgb(0, 96, 128);"&gt;"age"&lt;/span&gt;, &lt;span style="color: rgb(0, 96, 128);"&gt;"25"&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;dict.TryAdd(&lt;span style="color: rgb(0, 96, 128);"&gt;"age"&lt;/span&gt;, &lt;span style="color: rgb(0, 96, 128);"&gt;"25"&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Create/update/delete actions can be executed by calling one of Try* methods, which return &lt;strong&gt;true&lt;/strong&gt; on success, else &lt;strong&gt;false&lt;/strong&gt;. In the code sample, first attempt to add value “25” with key “age” is ok, and TryAdd return true. Second attempt is fail, and TryAdd() return false, and exception will not be generated. Other example:&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; t = &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;.Empty;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;Console.WriteLine(dict.TryGetValue(&lt;span style="color: rgb(0, 96, 128);"&gt;"nokey"&lt;/span&gt;, &lt;span style="color: rgb(0, 0, 255);"&gt;out&lt;/span&gt; t));&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Key “nokey” is not present in the dictionary, but TryGetValue() method doesn’t generate any exception, and only return false. You can remove an element as shown here:&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;Console.WriteLine(dict.TryRemove(&lt;span style="color: rgb(0, 96, 128);"&gt;"age"&lt;/span&gt;, &lt;span style="color: rgb(0, 0, 255);"&gt;out&lt;/span&gt; t));&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Using properties Values and Keys you can receive actual on the moment of call collections of values and keys of dictionary.&lt;/p&gt;
&lt;p&gt;So, you can see, that these data structures is very basic, and don’t contains tons of functions – only necessary things. I like this concept – it’s a base structures and too many functions is redundant. If you need something else, you can easily add it at any time.&lt;/p&gt;
&lt;p&gt;In addition to described data structures, .NET 4 beta 1 contains list ConcurrentLinkedList&amp;lt;T&amp;gt;. But I don’t cover it, because MSDN &lt;a href="http://msdn.microsoft.com/en-us/library/dd381935(VS.100).aspx"&gt;contains&lt;/a&gt; following warning: «&lt;em&gt;ConcurrentLinkedList(of T) is planned to be removed prior to the final release of Visual Studio 2010. Please&lt;/em&gt;&lt;em&gt; do not use this class&lt;/em&gt;». And in the .NET 4 beta 2 this collection is removed.&lt;/p&gt;
&lt;p&gt;Ok, I show you 4 basic thread-safe collections of data. In the next part of the article I show you BlockingCollection&amp;lt;T&amp;gt; – more complex and interest thread-safe storage. Stay tuned! :)&lt;/p&gt; &lt;img src="http://geekswithblogs.net/vitus/aggbug/135688.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Vitus</dc:creator>
            <guid>http://geekswithblogs.net/vitus/archive/2009/10/24/thread-safe-data-structures-.net-4.0-part-1.aspx</guid>
            <pubDate>Sat, 24 Oct 2009 04:20:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/vitus/comments/135688.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/vitus/archive/2009/10/24/thread-safe-data-structures-.net-4.0-part-1.aspx#feedback</comments>
            <slash:comments>21</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/vitus/comments/commentRss/135688.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>
