The Visual Studio Code Snippets Project Adds Parallel Programming Snippets
The November 2010 Release of the StyleCop Compliant Visual Studio Code Snippets open source project adds many parallel programming code snippets for the C# programming language. The code snippets are compatible with Visual Studio 2010.
If you work with the C# programming language and you use Visual Studio 2010, the code snippets are very useful to increase your productivity. For example, each time you want to create and start a new task, you usually write code to use a lambda function:
Task.Factory.StartNew(() =>
{
});
Then, you have to write the code within the lambda function. The project StyleCop Compliant Visual Studio Code Snippets provides a task snippet that inserts the previously shown lines of code.
StyleCop analyzes C# source code to enforce a set of style and consistency rules. The 78 code snippets included in the project insert StyleCop compliant code. Some of the code snippets replace the code snippets that ship within Visual Studio 2010. For example, the new version of the lock snippet acquires a lock on a synchronizationObject object.
First, you can insert a sync snippet that writes the following lines:
/// <summary> /// Defines a private thread synchronization object for the <see cref="T:Program"/> class. /// </summary> private object synchronizationObject = new object();
The new synchronizationObject private object includes documentation headers. Then, you can insert the new lock snippet that writes the following lines:
lock (this.synchronizationObject)
{
}
The project includes code snippets for the static members of the System.Threading.Interlocked class and for Parallel.For, Parallel.ForEach and Parallel.Invoke. For example, you can insert the pfor snippet that writes the following lines:
System.Threading.Tasks.Parallel.For(0, 10, index => {
});
You can read Doug Holland's post about the November 2010 Release of this project. In this post, you will find information about the most important features included in this release.

