Six Things That Will Surprise You About .NET 4.0

by Michael Kennedy

In this article, we will explore some of the new features of the .NET 4.0 as well as Visual Studio 2010. Some of these features are well-known, but others haven't gotten the press that they deserve. I've combed through .NET 4 to pull out the cool features that maybe didn’t get all the press – but should have. Read on and be pleasantly surprised!

[Note: Everything discussed below is based on .NET 4.0 and VS 2010 Beta 2]
 
#1 Visual Studio 2010                                                 
 
You may have already known...
 
code-oriented features are a major focus of the improvements for VS 2010. For example, one style of development where developers sketch out a scenario in code involving a set of classes before they are completely written was painful in VS 2008 (e.g. TDD). 
 
In this style of working, intellisense did all it could to get in your way and the IDE offered little to help move you forward. This gap was filled by 3rd party tools, most notably Resharper (http://www.jetbrains.com/resharper/).
 
In VS 2010, this capability will be built into the IDE -- can you say "CTRL-." anyone? See the sequence below for details.


But did you know...

that VS 2010 was rewritten in WPF and as part of that rewrite now has true multi-monitor support?

Yes, previously you could drag a build output window to a second monitor or the properties window to the side. But the part you really needed to split up, the code and designers, were solidly grounded in the one IDE window. 
 
Not in 2010, you can pull these free and put them on your second, or third monitors. This aids both when working on UIs (you can see the designer and code-behind) as well as when doing TDD (you can see the test code and production code side-by-side).





#2 ASP.NET
                                                        
 
You may have already known...
 
ASP.NET MVC is now integrated into VS 2010 and ships as part of .NET 4.0. In case you haven't heard of it, ASP.NET MVC is an alternative to the WebForms model that has been the backbone of ASP.NET for so many years. You can build well-factored, testable, and clean web applications more easily in MVC.
 
But did you know...
 
for the very first time an true open source will become and integral and supported part of Visual Studio and .NET? JQuery will now be part of all web projects created by VS 2010 by default. That does for ASP.NET WebForms, not just MVC projects. In fact, you can even open a support ticket with Microsoft concerning JQuery. You can read Scott Guthrie's original announcement for more details here



#3 WF 4.0                                               
 
You may have already known...
 
that Windows Workflow 4 has been completely rewritten for .NET 4.0. It's not even backwards compatible with .NET 3.5's version of WF. Basically WF 3 was a good try, but suffered from a couple of major problems that could not be overcome by simply refactoring the library.
 
But did you know...
 
WF 4 has a nice GUI workflow building designer that is part of the VS 2010 tools and moreover that designer is rehostable in your own Windows Forms or WPF applications. 
 
Why might you do this? Consider an application where there is a scriptable aspect that is for non-developer types of users. Instead of giving them a scripting language such as Python, you can build WF activities and provide them with the designer to wire them together. This would give your application essentially a visual programmability.





#4 Base-Class Libraries                                        

You may have already known...

.NET 4.0 has threading constructs like Parallel.For which are designed for leveraging parallelism and multi-core hardware in CPU-bound situations. These are a perfect compliment to things like the ThreadPool class which are indented for parallelism when latency in external systems (databases, web services, file IO, etc) is the bottleneck.

But did you know...

there will be a new collection namespace called System.Collections.Concurrent?
 
Here you will find lock-free, thread-safe collections such as ConcurrentQueue<T>. As we move from single core systems, to multi-core systems, and then into many-core systems (say 64 cores) these types of lock free objects will become increasingly important.
 




#5 WPF                                             
 
You may have already known...
 
that the WPF and Silverlight designers in VS 2010 are greatly improved. You now have some features available that were only available in Expression Blend previously (e.g. data-binding)
 




But did you know...
 
the text rendering stack in WPF 4 has been completely rewritten.
 
Now text looks as clear in WPF as it does in GDI+ with ClearType enabled. This includes a host of edge cases, such as when the text is re-rendered via a VisualBrush, is used in animations, or even 3D text. Once again Scott Guthrie comes through with a great WPF 4 writeup on his blog.




#6 CLR and Base-Class Libraries            
 
You may have already known...
 
that .NET 4 ships with an entirely new runtime. There have been a number releases of .NET lately (2.0, 3.0, 3.5, 3.5 SP1) but all of these versions of .NET have run on the 2.0 runtime. For the first time since 2005, .NET 4 we'll have a completely updated runtime with new GC modes, side-by-side in-process execution of the 2.0 and 4.0 runtime, the loosening of COM interop rules with the No PIA feature (no Primary Interop Assemblies required).
 
But did you know...
 
there are new numerical types including BigInteger which supports arbitrarily big integers and ComplexNumber for modeling systems with advanced mathematical formulas which involve the complex number system.




You'll have to look around a bit to find these types however as they are not referenced by default. They are in the new System.Numerics library.

Summary                  
 
.NET 4 is going to be an exciting release with a some very polished libraries and tools. This article just touched on a few of them. 
 
  1. Visual Studio 2010 Multi-monitor Support
  2. JQuery is now part of ASP.NET
  3. WF 4 Has a Rehostable Designer
  4. BCL has New Thread-Safe Collections
  5. WPF has Real Text Support
  6. CLR and BCL has new Numerical Types
Check out our new .NET 4 courses, ASP.NET MVC, LINQ with the Entity Framework 4.0, WF4, What's New in .NET 4.0. Also watch for new courses on Visual StudioTeam System 10, SharePoint 2010, Enterprise Patterns, and Pragmatic Cloud Computing for .NET Developers.  Contact us here requests@develop.com or call 800.699.1932 for more information.


Michael Kennedy
 is an instructor for DevelopMentor where he specializes in core .NET technologies as well as agile and TDD development methodologies. Keep up with Michael via his Web site and blog at http://www.michaelckennedy.net or on Twitter: @mkennedy.