.NET Framework 4.0 Beta 2

A short post about getting acquainted with the new framework.
Beta 2 turned out to be quite usable, so RunServer now supports it too. Among the clear improvements, I noticed more correct ThreadPool behavior — fewer threads get spawned, fewer context switches — and Server GC threads also became noticeably lighter on resource usage. I haven’t touched the new C# 4.0 features or CLR 4.0 in general — compatibility with .Net Framework 2 and stability matter more to us than code embellishments and questionable perks like Parallel Extensions.
It was a bit disappointing that VS 2008 doesn’t let you pick the new Target Framework. You have to use VS 2010 or build the project via MSBuild from the command line. For my own purposes I found a fairly simple solution to this — specify the framework version through app.config and build while targeting the regular 2.0 framework:

<?xml version="1.0"?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0.21006"/>
    <supportedRuntime version="v2.0.50727"/>
  </startup>
</configuration>

With this config, the .exe will first try to start under the .Net 4.0 Runtime, and fall back to 2.0 if that’s not available. The resulting files end up a bit larger than with a “proper” 4.0 build, but I didn’t notice any difference in performance.

Originally published 2010-02-09.