Assisting with Windows Azure Kick Start Event in Milwaukee May 17th, 2012

I get the pleasure of helping host the Windows Azure Kick Start MSEvent to be held at the Microsoft offices in Waukesha, WI on May 17th, 2012.

Windows Azure Kick Start Milwaukee event Message HTML 2012 04 23 20 13 36 Assisting with Windows Azure Kick Start Event in Milwaukee May 17th, 2012

Event locations
Select a city near you

Location Date
Downers Grove, IL May 1
Chicago, IL May 3
Waukesha, WI May 17

FREE Events
Seating is limited,
so register today.

Events run from
9:00AM – 5:00PM

Spend a day with some of the nation’s leading cloud experts in learning how to build a web application that runs in Windows Azure. We will show you how to sign up for free time in the cloud, and how to build a typical web application using the same ASP.NET tools and techniques you already use today. We will explore web roles, cloud storage, SQL Azure, and common scenarios. We will save time for open Q&A, and event cover what should not be moved to cloud. This will be a hands-on event where you will need a laptop configured with the required pieces. We will have help onsite to get the right bits installed as well. Lunch and prizes will be provided.If you can’t join us in person please check out Azure on your own at http://aka.ms/isLP.
Session Requirements

  • A computer or laptop: Operating Systems Supported: Windows 7 (Ultimate, Professional, and Enterprise Editions); Windows Server 2008; Windows Server 2008 R2; Windows Vista (Ultimate, Business, and Enterprise Editions) with either Service Pack 1 or Service Pack 2
  • One click install of Windows Azure SDK and required software using Web Platform Installer.
  • The sample code and handbook for the labs will be provided at the event.
  • Consider bringing a power strip or extension cord.

To register
Select a city near you or to register by phone, call 1-877-MSEVENT.  .  If you can’t attend please visit http://aka.ms/isLP.

 

Posted in Cloud, Development, Technical Community | Tagged , , | Leave a comment

Speaking at the Fox Valley Day of .NET April 28th, 2012

Kinect for Windows text 300x168 Speaking at the Fox Valley Day of .NET April 28th, 2012I will be speaking for the fifth consecutive year at the Fox Valley Day of .NET (#FVDODN). Details about the presentation are below. Check out some of great content and don’t forget to register… Fox Valley DoDN

Get Yourself Kinect-ed! – Greg Levenhagen

The Kinect is waiting for you! All you have to do is reach out and make a move, literally. Since the Kinect SDK, Kinect for Windows hardware and commercial support for non-XBOX 360 applications has been released, you’re able to create amazing applications. Natural user interfaces are making their way to mainstream devices. By getting yourself Kinect-ed, you can be part of that revolution. Come see what the Kinect SDK offers, how to utilize the Kinect hardware features and most importantly how to develop with the Kinect.

Posted in Development, Technical Community | Tagged , | Leave a comment

HTML5 and Azure Bootcamp on April 27th, 2012


NewBootCampLogo HTML5 and Azure Bootcamp on April 27th, 2012

The Fox Valley .NET Users Group (#fvnug) is helping to host an HTML5 and Azure Bootcamp to be held at the Radisson (Paper Valley) hotel on College avenue in Appleton, WI. Please check out the details and register here.

Posted in Cloud, Development, Technical Community, Web | Tagged , , | Leave a comment

Speaking at the Windows 8 Developer Event in Chicago April 26th, 2012

I am speaking at the MSEvent – Windows Developer Event to be held at Navy Pier in Chicago, IL. Here is some more information. I hope to see you there! Register here Windows 8 Developer Event.

Windows 8 Developer Event in Chicago Message HTML  2012 04 23 19 37 071 Speaking at the Windows 8 Developer Event in Chicago April 26th, 2012
Date April 26, 2012
Time 9:00AM – 5:00PM
Location

Navy Pier
600 East Grand Avenue

Chicago, IL

FREE Event

Seating is limited,
so register today.

   

Windows reimagined.Learn everything you need to start building Metro-style apps for Windows today at our free, full-dayWindows Developer Event.We’ll show you how to use Visual Studio to code fast, fluid, immersive and beautiful Metro-style applications in HTML5/JavaScript, XAML/C# and C/C++.

Your investments in these languages carry forward, making Windows a no-compromise platform for developers.Whatever language you choose, your app gets deep integration with the Windows shell, including notifications, live tiles, deep links, and contracts with other apps. And now you can build once and support all Windows customers, no matter what type of PC they have—from tablets to laptops to convertibles to desktops.Seating is limited and registration is not guaranteed. Secure your spot today!Notes

This free event is brought to you by Microsoft. However, you are responsible for booking and funding your own travel and accommodations. Please notethat there is limited space available for this event, so be sure to register early.

 

Posted in Cloud, Development, Mobile, Technical Community | Tagged , , , , , , , , | Leave a comment

Speaking at the Chicago .NET Users Group April 18th, 2012

I will be speaking on April 18th at the Chicago .NET Users Group (CNUG) meeting. Scott Seely will be speaking for the Chicago Azure Cloud Users Group just before me at the same location. Come see us both! My topic and abstract is below.

Get Yourself Kinect-ed! – Greg Levenhagen

Kinect development used to mean hacking without any support, but now that the Kinect SDK, Kinect for Windows hardware and commercial support for non-XBOX 360 applications has been released, the full power of the Kinect is unleashed. Come see how to start developing with the Kinect, using its hardware features and what the Kinect SDK provides.

Posted in Development, Technical Community | Tagged , , | Leave a comment

Speaking at the Twin Cities Code Camp 2012

I will be speaking the weekend of April 14th and 15th in Minneapolis at the Twin Cities Code Camp! The information about my session is below. If you’re interested in attending, please register now using EventBrite. For more event information, please go to the TCCC website. I hope to see you there.

Parallel Programming in .NET and Azure - Greg Levenhagen

Parallel programming remains a difficult task, but the .NET framework keeps making things easier for developers. With the various constructs available, like the addition of the Task Parallel Library in .NET 4, it is important to know what is appropriate for different situations. Devices continue to gain cores and the cloud offers easily distributed computing, so developers should understand how to utilize the environments. Come for a walk-through of how and when to use these constructs, whether that is in the cloud, a mobile device, desktop application or the web.

Posted in Cloud, Development, Technical Community | Tagged , , , , | Leave a comment

Azure Storage Configuration Management

Deploying applications to Azure requires a change in the way of thinking about configuration. When roles can be spun-up at any time, the configuration settings will be what the deployment package contains. This means changing configuration within a role will most likely lose those changes when Azure moves a role, a role crashes or you add another role. The key is to make sure that the deployment package is up to date. By using the abstracts below, a developer can write code that works inside and outside of Azure.

A Windows Azure project contains configuration files for each environment called ServiceConfiguration.*.cscfg. You can create more than the default provided, which are Local and Cloud. Keeping the Azure Storage connection string and other settings in these files allows for greater portability.

By setting the CloudStorageAccount‘s publisher, the developer can read configuration values differently than strictly using ConfigurationManager. Under a Role’s project properties, browse to the Settings tab. For this example, you’ll want to click “Add Setting” and specify the details for Name and Type as below. The DataConnection setting will be used to store the connection string for Azure Storage.

AzureRoleSettings1 Azure Storage Configuration Management

For the Value, notice the ellipse button. It will provide a popup with the following.

AzureRoleSettings2 Value Azure Storage Configuration Management

When using the storage emulator, the Value will be set to “UseDevelopmentStorage=true”. The focus of this post is leave the configuration management in these settings as much as possible. This helps to allow the code to remain unchanged when moving between environments. There is a Service Configuration dropdown on the Settings tab that should be changed and the appropriate values specified for each scenario. For example, specify use of development storage for Local and specify the account credentials for Cloud.

Please note that the code shown below can be refactored to live in different places. It doesn’t have to be put into the global.asax or in each Controller for MVC projects. Using WebActivator, base classes and helper classes are worth considering.

Setting the configuration publisher within the Application_Start method in the global.asax file is the first action to take.

		protected void Application_Start()
		{
			AreaRegistration.RegisterAllAreas();

			RegisterGlobalFilters(GlobalFilters.Filters);
			RegisterRoutes(RouteTable.Routes);

			BundleTable.Bundles.RegisterTemplateBundles();

			CloudStorageAccount.SetConfigurationSettingPublisher(
				(configurationName, configurationSettingPublisher) =>
					configurationSettingPublisher(RoleEnvironment.GetConfigurationSettingValue(configurationName)));
		}

As the code self documents, the SetConfigurationSettingPublisher method takes a lambda expression as an argument. The configurationName variable is of type string and the configurationSettingPublisher variable is of type System.Func<string, bool>.

In case you don’t have a tool to automatically import using statements, the following are required.

	using Microsoft.WindowsAzure;
	using Microsoft.WindowsAzure.ServiceRuntime;

Before moving on, I want to point out that I’m using a static constants class to keep hard-coded strings in one place. This hard-coded string bridges the gap between code and the settings, but the value is what we are concerned about changing.

	public static class ConfigurationConstants
	{
		public const string DataConnection = @"DataConnection";
	}

Now that the wiring up of the Storage configuration is done, we need to consume it. For this example, let us use a Controller class from an ASP.NET MVC4 project that is specified as a WebRole. A few steps are needed to get access to the TableServiceContext.

	using System.Web.Mvc;

	using Microsoft.WindowsAzure;
	using Microsoft.WindowsAzure.ServiceRuntime;
	using Microsoft.WindowsAzure.StorageClient;

	public class HomeController : Controller
	{
		private readonly CloudStorageAccount cloudStorageAccount;
		private readonly CloudTableClient cloudTableClient;
		private readonly TableServiceContext tableServiceContext;

		public HomeController()
		{
			this.cloudStorageAccount = CloudStorageAccount.FromConfigurationSetting(ConfigurationConstants.DataConnection);

			this.cloudTableClient = new CloudTableClient(this.cloudStorageAccount.TableEndpoint.AbsoluteUri, this.cloudStorageAccount.Credentials);

			this.tableServiceContext = this.cloudTableClient.GetDataServiceContext();

			string someOtherSetting = RoleEnvironment.GetConfigurationSettingValue(ConfigurationConstants.SomeOtherSetting);
		}
	}

Inside the constructor, the first statement is retrieving the configuration setting for the data connection. This allows changing the setting from the project level based on the service configuration (Debug, Cloud, etc.) and not having to change any code when switching environments. If the CloudStorageAccount.DevelopmentStorageAccount option is used instead of the FromConfigurationSetting method, it is essentially using a hard-coded value.

The second statement is creating a CloudTableClient, which can be replaced with a CloudQueueClient or CloudBlobClient. The constructor for the CloudTableClient is taking in a Uri and a StorageCredentials as arguments. By using the overload for the Uri and using an AbsoluteUri for the value, it avoids complications with changing Endpoints (Http, Https, TCP).

From here, the third statement is simply gaining access to the TableServiceClient. The last statement is showing how to read a setting that isn’t going through the CloudStorageAccount.

You’ll most likely want to have your table name(s) specified in configuration or use whatever mechanism works for your business case. Also, don’t forget to properly check if the table exists before using it. There are methods on the CloudTableClient for doing that type of management.

We all want to avoid hard-coding, so whatever approach you take make sure it’s not going to limit you or cause problems later in the application’s life.

Posted in Cloud | Tagged , | Leave a comment

Azure Geographical Location Restriction

Requirements often dictate that storage and/or processing be done in a specific geographical location. I often get asked, “Does Azure have geo-location specific support?”  Most of those questions originate from the need for compliance that is either from industry or government. Azure allows specification of geographical regions or affinity groups. Geographical regions are related to the data centers, like North Central US, South Central US, Anywhere US, East Asia, North Europe, and so on. The list of options will grow as more data centers are added.

When creating a New Hosted Service account in Azure, the following options are provided. This post is bringing light to the choices under the Choose a region or affinity group.

Windows Azure Platform GeoLocation Hosting Choose a Region Azure Geographical Location Restriction

Instead of selecting a region, it is possible to specify an affinity group. Affinity groups are hints to Azure that essentially state that everything within the group should be as close in proximity as Azure will allow. That usually means keeping items within the same data center, which besides having the benefit of geo-location, can sometimes offer performance improvements for communication.

The drop down for affinity groups allows for selection of existing groups or creation of a new one.

Windows Azure Platform GeoLocation Hosting Select Affinity Azure Geographical Location Restriction

When creating a new affinity group, it allows for specification of a region just like what was shown previously.

Windows Azure Platform GeoLocation Hosting Create Affinity Azure Geographical Location Restriction

The previous screenshots are for a New Hosted Service, so here is what it looks like for creating a Storage account in a similar fashion. The current choices for Regions when creating an Azure Storage account are shown.

Windows Azure Platform GeoLocation Storage Choose Region Azure Geographical Location Restriction

In the case for choosing an affinity group, notice the existing group created by the hosting account. By selecting the same group, Azure will keep the two accounts close in proximity.

Windows Azure Platform GeoLocation Storage Choose Affinity Azure Geographical Location Restriction

These features offer great control of where the processing and storage take place within the Azure ecosystem. When there are concerns about governmental, political and compliance requirements, Azure has some nice answers!

Posted in Cloud, Security | Tagged , | Leave a comment

An Overview of .NET Threading and Tasks

Concurrent programming aims to execute potentially different pieces of work at the same time and parallel computing aims to reduce a piece of work into multiple pieces to execute concurrently. Parallel computing has been around for decades, but it has remained a difficult problem. It aims to support multi-core, multi-CPU and distributed systems. The continued work for supporting these paradigms is great, because it has always been an issue to keep user interfaces responsive and handle operations quickly. In recent years, consumption of asynchronous services has exploded and parallel operations to some extent. As devices continue to grow and gain a significant amount of cores, expect parallel and asynchronous functionality to become more and more common.

With the release of .NET 4, Microsoft added a new namespace under the System.Threading namespace called System.Threading.Tasks. All of the previous threading abilities are still available, but the new additions provide a different way to work with multi-threaded constructs.

With the evolution of multi-threaded capabilities within the .NET framework, things can get a little confusing. Here is a brief history with some notes.

What are Threads?

When running an application or program, it is executing a process. Multiple processes can be executed concurrently, like when an email client and a web browser are used at the same time. A look at what is going on inside of a process shows threads. In much of the same way that a process is to an operating system, a thread is to a process. The major difference is that processes do not share any memory between them and threads have that ability in a restricted fashion. Synchronization of mutable objects between threads is often a pitfall for developers.

Threads in .NET 1.0+

In the System.Threading namespace, the Thread class exists along with with other classes to provide fine-grained multi-threading capabilities for the .NET framework. This means thread synchronization support and data access using classes like the following.

  • Mutex – Used for inter-process communication (IPC).
  • Monitor – Provides a mechanism that synchronizes access to objects.
  • Interlocked – Provides atomic operations for variables that are shared by multiple threads.
  • AutoResetEvent – Notifies a waiting thread that an event has occurred.
  • Semaphore – Limits the number of threads that can access a resource or pool of resources concurrently. (Added with .NET 2.0)
  • and many more.

The ThreadPool in .NET 1.0+

The System.Threading.ThreadPool class provides a group of system managed threads to the application and is often a more efficient way to handle multi-thread programming. This is because it helps the developer avoid having threads spending a majority of the time waiting on another thread or sitting in a sleep state. In order to execute a method in the ThreadPool, you can call QueueUserWorkItem that specifies the method to execute and an optional parameter for any data that is needed. It is also allowed to use an asynchronous delegate with BeginInvoke and EndInvoke methods. The method specified will begin executing when a Thread in the ThreadPool becomes available.

Each process is limited to one system level thread pool. The ThreadPool manages background threads, so if all foreground threads exit, then the ThreadPool will not keep the application alive. In this case, finally and using blocks are not handled correctly, so using a method call to Join, Wait or Timeout to avoid this should be practiced.

The default ThreadPool limits are:

  • .NET 2.0 – 25 threads
  • .NET 3.5 – 250 threads
  • .NET 4.0 (32-bit) – 1,023 threads
  • .NET 4.0 (64-bit) – 32,768 threads

The BackgroundWorker in .NET 2.0+

When there is a need to execute some non-UI process, the System.ComponentModel.BackgroundWorker will spawn a new thread and execute the operations. It offers a progress indicator to report back to the calling thread, forwarding of exceptions and canceling the processing. If the situation warrants using multiple BackgroundWorkers though, consideration should be given to the Task Parallel Library.

The BackgroundWorker class follows the event-based asynchronous pattern (EAP). The EAP means it abstracts and manages the multi-threading capabilities while allowing for basic interaction via events. When the words Async and Completed are appended to a class methods, it may be implementing some form of the EAP. Another similar pattern is the asynchronous programming model (APM), which use Begin and End methods. Both the EAP and APM work well with the new .NET 4.0 construct Task that is mentioned later in this post.

Besides directly using the BackgroundWorker implementation, it can also be subclassed. It would involve overriding the OnDoWork method and handling of the RunWorkerCompleted and ProgressChanged events in the consuming class. The subclass provides a better level of abstraction for a single asynchronously executing method.

BackgroundWorker uses the ThreadPool, so it benefits from improvements that have been made with later versions of the .NET framework. Using the ThreadPool also means that calling Abort should not be done. In a case where you want to wait for completion or cancellation of the BackgroundWorker, you may want to consider using the Task Parallel Library.

The Dispatcher in .NET 3.0+

The System.Windows.Threading.Dispatcher class is actually single-threaded in that it doesn’t spawn a new thread. It places operations in a state to execute when BeginInvoke is called, but it executes on the same thread that it’s instantiated in and then communicates to another thread. The reason for the Dispatcher’s existence boils down to thread affinity. A user interface Control or DependencyObject is forced to strictly belong to its instantiating thread. For example, in the case of Windows Presentation Foundation (WPF) and Silverlight , the Dispatcher class allows a non-UI thread to “update” a TextBox control’s Text property on the UI thread through marshaling.

Parallel LINQ (PLINQ) in .NET 4.0+

PLINQ is a parallel implementation of the Language-Integrated Query (LINQ) pattern. Just like LINQ to Objects and LINQ to XML, PLINQ can operate against any IEnumerable or IEnumerable<T>. The namespace for PLINQ is System.Linq.ParallelEnumerable, but this implementation of LINQ doesn’t force parallel operations on everything. There are additional methods too, such as:

  • AsParallel – This is how to enable PLINQ. If the rest of the query can be parallelized, it will do so.
  • AsSequential<T> – Will turn a previously parallelized query back into a sequential one.
  • AsOrdered – Preserve ordering until further instructed by something like an order by clause or AsUnordered<T>.
  • AsUnordered<T> – No longer preserve ordering of the query.
  • ForAll<T> – Allows for processing in parallel instead of requiring a merge back to the consuming thread.
  • Aggregate – Provides intermediate and final aggregation of results.
  • and a few more.

The AsParallel method is very straightforward to try, as the call is made directly on the data source within a LINQ query or foreach loop.

PLINQ does not guarantee that the query will be executed in parallel. It checks if it is safe to parallelize and if doing so will likely provide an improvement. If the check conditions are not satisfied, it will execute the query sequentially. By using the optional WithExecutionMode, PLINQ will guarantee parallel execution.

Exceptions are bundled up together from all the threads and placed into an AggregateException, which you can then iterate through to process each exception or flatten into a single exception. This special type of exception is used in other areas of .NET 4.0 multi-threading too.

Custom partitioning is offered for a way that a developer can specify how the data source should be parallelized. For instance, if the data source contains hundreds of thousands of rows and testing shows that some of the threads are only given a few hundred rows, a partition can be created on the data source accordingly. Custom partitioning is done to the data source before the query and the resulting object replaces the data source within the query.

The Task Parallel Library (TPL) in .NET 4.0+

The TPL is a collection of constructs in the System.Threading and System.Threading.Tasks namespaces. This post has split PLINQ out above because it resides in a different namespace, but some documentation refers to them together. Some of the same characteristics mentioned in PLINQ apply here too, since PLINQ actually reduces a query into Tasks (defined below).

As mentioned in the opening statement, all of the fine-grained constructs of multi-threading are still available, so what is the need for the TPL? The goal is to make parallel programming easier. The TPL uses an algorithm to dynamically update during the execution for the most effective utilization of resources. Under PLINQ, there is a section on custom partitioning, which is to override the built in partitioning. Collectively, the TPL handles the the default partitioning of data, the ThreadPool, cancellations and state.

“The Task Parallel Library is the preferred way to write multi-threaded and parallel code.” – MSDN

The Parallel Class

The Parallel class provides the methods For, Invoke and ForEach to process operations in parallel.

  • For – parallel equivalent of the for keyword
  • Invoke – executes Action delegates in parallel
  • ForEach – parallel equivalent of the foreach keyword
The Task Class

Tasks offer much of the same functionality as previous solutions like Thread, but also include continuations, cancellation tokens, forwarding and context synchronization. The Parallel class reduces its For, ForEach and Invoke methods into Tasks. A Task is semantically the same as a Thread, but does not require creating an operating system thread, because it is put into the ThreadPool. Also, multiple Tasks may run on the same Thread. That can be confusing at first, but it offers a lot of flexibility.

In comparison to directly using the ThreadPool by starting a parallel execution of a method by calling QueueUserWorkItem, the Task class has a Factory property which is of type TaskFactory. From the TaskFactory, a call to StartNew and passing in a lambda expression will queue up the work. By default, Tasks will be placed in the ThreadPool. If the option for a long running operation is specified, the Task will be created on a separate thread. Regardless, these ways of creating a Task mean that execution will be in a background thread. If you want a reference to the Task created, the StartNew method returns a Task object. Using that object, traditional functionality is available for things like waiting. Tasks also support setting up parent-child relationships which can be very useful for wait and continuation operations.

Continuations

Continuations provide a way to execute code after a Task completes with the option of using the result from the Task. Continuations provide a very nice fluent syntax that resembles having a Completed method tied to an event. The fluent syntax isn’t required if there is a reference to the Task so determination can be done of what to continue with. Multiple continuations can be specified to handle error conditions, cancelations and normal completion of a Task. One of the major goals of continuations was to provide a situation for non-blocking on waiting for a Thread or Task to complete.

Parallel Primitives and Data Structures in .NET 4.0+

Thread Safe Collections

In .NET 1.0, the System.Collections namespace provides some built in support for thread safety with the Synchronized property. Microsoft states that the implementation is not scalable and is not completely protected from race conditions.

With .NET 2.0, the System.Collections.Generic namespace brought generic collections, but removed any thread safe capabilities. This means the consumer needs to handle all synchronization, but the type safety, improved performance, and scalability are significant.

Bring in .NET 4.0 and the addition of System.Collections.Concurrent. This provides even better performance than the .NET 2.0 collections and provides a more complete implementation of thread safety than .NET 1.0. This namespace includes:

  • BlockingCollection<T>
  • ConcurrentBag<T>
  • ConcurrentDictionary<TKey, TValue>
  • ConcurrentQueue<T>
  • ConcurrentStack<T>
Lazy Initialization

Lazy initialization of objects comes into play when those operations are expensive. The application may not require the expensive objects, so using these new constructs can have a significant impact on performance.

  • Lazy<T> – Thread-safe lazy initialization.
  • ThreadLocal<T> – Lazy initialization specific to each thread.
  • LazyInitializer – Alternative to Lazy<T> by using static methods.
Barrier

The Barrier class is interesting because it allows for Threads to have checkpoints. Each Barrier represents the end of some block or phase of work. At at checkpoint, it allows for specifying a single thread to do some post-block work before continuing. Microsoft recommends using Tasks with implicit joins if the Barriers are only doing one or two blocks of work.

SpinLock and SpinWait

The SpinLock and SpinWait structs were added because sometimes it’s more efficient to spin than block. That may seem counter-intuitive, but if the spin will be relatively quick it can produce major benefits in a highly parallelized application because of not having to perform a context switches.

Miscellaneous Notes

Deadlock Handling

In the case of a deadlock, SQL Server will determine one of the offending threads and terminate it. This doesn’t happen within .NET. A developer must take careful consideration to avoid deadlocks and should use timeouts to help avoid this situation.

Forcing Processor Affinity

In some cases, running in parallel can be problematic. One way to avoid such complications is to set the processor affinity on through the Process class. Call the GetCurrentProcess method and then use the ProcessorAffinity property to get or set the affinity as needed.

Debugging Parallel Applications in Visual Studio 2010+

There are two new additional debugging windows added with Visual Studio 2010. They are the Parallel Stacks window and Parallel Tasks window. The Parallel Stacks window provides a diagram layout based on either Tasks or Threads and lets the developer see the call stack for each construct. The Parallel Tasks window resembles the Threads window with a grid of all Tasks.

Task Parallel Library (TPL) in .NET 4.5

The most notable changes in .NET 4.5 will most likely be the async and wait keywords. There is a major focus on making continuations as fast as possible and the wait keyword will hopefully simplify writing continuations.

Conclusion

There is a lot of support for multi-threaded, parallel and asynchronous programming within the .NET framework. Hopefully you now have a better understanding of what each construct does. The latest addition, the TPL, has some major improvements and should be added to your toolbox. Pay attention to what .NET 4.5 will provide as it aims to make things even easier.

Further Reading

Posted in Development | Tagged , , , , , , , , , , | Leave a comment

Visual Studio 2010 Merge and Compare with KDiff3

Although the default compare tool built in with Visual Studio/TFS is adequate, I find situations where third party solutions have automatically resolved situations that the default tool did not. I have used a variety of tools and prefer KDiff3, but WinMerge, Beyond Compare, and others are all great options.

After setting up Visual Studio to use a custom tool, it will automatically use it for both comparisons and merges without prompting you. The automatic calculation of conflicts on check-ins is still done on TFS. This means it may list a certain number of conflicts, but when you open them locally with your custom tool they may all be resolved automatically. It may seem like it’s an extra step, but if you were just using the built-in tool, you would have handle all of the conflicts.

Go to Tools -> Options from the main menu.

Visual Studio Options Menu1 218x300 Visual Studio 2010 Merge and Compare with KDiff3

Then go to Source Control -> Visual Studio Team Foundation Server.

Visual Studio Tools Options Source Control1 300x157 Visual Studio 2010 Merge and Compare with KDiff3

From here click on Configure User Tools button, which will bring up the following popup.

Visual Studio Tools Options Source Control Configure User Tools1 300x181 Visual Studio 2010 Merge and Compare with KDiff3

After clicking Add, you will be given the opportunity to provide information for using a custom merge and compare tool.

Visual Studio Tools Options Source Control Configure Tool1 300x162 Visual Studio 2010 Merge and Compare with KDiff3

You can see from the drop down there are two choices that correspond to our tools. Third party tools use different command line arguments for specifying compare and merge operations, so we need to specify them separately.

  • For the extension textbox, enter “.*” without the quotes. This will use the tool you specify for all of the file types.
  • Select the operation for Compare or Merge.
  • In the Command textbox, click the ellipse button and find the executable to the third party utility you have installed.
Visual Studio Tools Options Source Control Configure Tool Options1 300x154 Visual Studio 2010 Merge and Compare with KDiff3

You can see the right arrow is clicked in the figure above and it expands a help menu. This menu is specifying how Visual Studio will provide the files, options and information to the utility.

For this example I’m using KDiff3. The arguments I use for compare are:

    %1 –fname %6 %2  –fname %7

For the merge arguments, I use:

    %3 –fname %8 %2  –fname %7 %1 –fname %6 -o %4

Tools Used:

  • KDiff3 0.9.95
  • Visual Studio 2010 SP1
Posted in Application Lifecycle Management, Development | Tagged , , , , , | Leave a comment