In my first post of this Visual Studio 11 series, I discussed some of the language-level innovation in the Visual Studio 11 Developer Preview.  In this second post, I’ll take a look at some of the improvements that have gone into the .NET Framework 4.5 Developer Preview.

Languages enable developers to express their intentions for the behavior of their programs.  To be as productive as possible, however, developers rely on runtimes and libraries to encapsulate commonly needed functionality.  Our teams have augmented.NET 4.5 significantly to enable developers to be as productive as possible while building out rich, reliable, and high-performance software in managed code.  My goal here is not to detail every new feature that’s been included (such an endeavor would warrant an entire book), or even to touch on every area of the Framework that’s been improved. Instead, I simply want to highlight a few additions that I believe are representative of the forward strides we’re making. For a broader look at what’s new in .NET 4.5, I recommend Joshua Goodman’s talk from //BUILD/ as well as the MSDN documentation on the topic.

Performance

For the .NET Framework 4.5, a lot of effort has gone into improving performance, both in terms of improving the performance of existing code as well as into providing new support for writing code that just runs faster, that’s more responsive, and that’s more scalable.

The Common Language Runtime (CLR) team has focused heavily on improving the performance of the runtime environment itself.  With additions like background server garbage collection, multi-core background JIT compilation, and profile-guided optimization, managed applications (especially those on the server) can now start faster and run with better throughput and lower latency.

Performance improvements extend beyond the runtime execution environment, as core components throughout the Framework have been rewritten internally to provide improved performance in key scenarios.  For example, the Stream class in .NET sits at the heart of most I/O-related operations, and asynchronously reading and writing with Stream is extremely common; these operations now have significantly less overhead in .NET 4.5.  As another example, ItemsControl in Windows Presentation Foundation (WPF) has been made much faster at handling certain kinds of data.

This work in streams is part of a larger focus on asynchrony in this release. As I mentioned in my previous post on languages, C# and Visual Basic have both been extended with first-class language support for writing asynchronous code.  That support extends well beyond the languages and into the libraries in the .NET Framework.  New task-based APIs have been added across the Framework, including in core Base Class Library (BCL) types, throughout the networking and Web services stacks, in the System.Xml and System.Data libraries, and more.

For more information, I recommend the following talks from //BUILD/:

Networking

It’s relatively rare these days to see an isolated application, one that doesn’t communicate in one way or another.  .NET has historically been rich with high-quality networking libraries, whether for low-level socket-based programming or for high-level communication via Web services.  .NET 4.5 builds upon that foundational support to enable the development of increasingly connected applications. While there are a multitude of interesting networking-related improvements in the .NET Framework 4.5, I want to call attention to three in particular.

WebSockets is a new bidirectional communication protocol that supports low-latency communications between client and server. It's great for implementing interactive applications, such as online games, that benefit from server to client "push," and .NET 4.5 includes support for WebSockets both in ASP.NET and in Windows Communication Foundation (WCF).  This release of .NET also sports the new HttpClient class, which enables clients and servers to easily and efficiently consume existing web APIs.

The other advance I want to call attention to is the integration of Tasks with WCF.  With the aforementioned language support, asynchronous APIs across the Framework are being exposed via tasks.  Beyond these APIs included in .NET, however, there are also APIs generated for you by Visual Studio.  One significant source of such APIs is for WCF Web service endpoints, as created by the Add Service Reference… dialog.  In previous releases, this tool by default only generated synchronous operations, and you could use the advanced configuration dialog to opt-in to having asynchronous operations exposed.  Now in Visual Studio 11 Developer Preview, by default the tool will not only generate asynchronous operations, it will do so using the task-based asynchronous pattern.

 

This means that all Web services to which you add service references will immediately support being awaited in asynchronous methods.  Here’s an example of using one such generated proxy to make asynchronous calls to search Bing:

For more information on the networking improvements in .NET 4.5, I recommend the following talks from //BUILD/:

Interop

A look at advancements in the .NET Framework would not be complete without an acknowledgement that the Framework itself contains only one of the sets of libraries your applications use.  In addition to all of the libraries from the .NET Framework that you rely upon, you also rely upon libraries of your own creation and of those created by 3rd-parties.  Historically, many of the libraries used in your applications have been thin wrappers on top of operating system functionality exposed by Windows… accessing the file system, accessing audio and video devices, and more.  Since the first release of .NET, the CLR has provided the ability to interop with such capabilities, but doing so has rarely been a trivial exercise.

With .NET 4.5 and with the advent of the Windows Runtime (WinRT), the need to create such interop wrappers becomes a thing of the past.  Through advancements in the CLR, your .NET applications can reference the metadata files for these components, and the CLR takes care of the interop details necessary to enable you to use these components as you would other .NET libraries.  This is a terrific productivity boon for developers.

For more information on the interop improvements in .NET 4.5, I recommend the following talks from //BUILD/:

There is a huge amount of functionality I’ve skipped past and glossed over in this post.  The BCL, the Managed Extensibility Framework (MEF), System.Xml, System.Net, WPF, ADO.NET, ASP.NET, WCF, Windows Workflow Foundation, Parallel Computing, and on… they’ve all received good attention in this release, and I’d encourage you to explore on your own to learn more about the work the teams have delivered.

Namaste!