This recipe shows a very simple scenario, comparing the performance of a usual dictionary collection with the concurrent dictionary in a single-threaded environment.
To work through this recipe, you will need Visual Studio 2012. There are no other prerequisites. The source code for this recipe can be found at BookSamples\Chapter6\Recipe1
.
To understand the difference between performance of a usual dictionary collection with the concurrent dictionary, perform the following steps:
Start Visual Studio 2012. Create a new C# Console Application project.
In the
Program.cs
file add the followingusing
directives:using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics;
Add the following code snippet below the
Main
method:const string Item = "Dictionary item"; public static string CurrentItem;
Add the following code snippet inside the
Main
method:var concurrentDictionary = new ConcurrentDictionary...