Channels ▼

Gaston Hillar

Dr. Dobb's Bloggers

The Visual Studio Code Snippets Project Adds Parallel Programming Snippets

December 02, 2010

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.

Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 


Video