Using async-await on .net 4

Microsoft released the Async Targeting Pack (Microsoft.Bcl.Async) through Nuget as a replacement for the AsyncCTP. You can read more about it here: http://blogs.msdn.com/b/bclteam/archive/2013/04/17/microsoft-bcl-async-is-now-stable.aspx. You can read about the previous version here: http://blogs.msdn.com/b/lucian/archive/2012/04/24/async-targeting-pack.aspx. As this pack is officially supported, I now believe the best option for targeting XP + async would be using Visual Studio 2012 … Read more

What is the best way to implement a “timer”? [duplicate]

Use the Timer class. public static void Main() { System.Timers.Timer aTimer = new System.Timers.Timer(); aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent); aTimer.Interval = 5000; aTimer.Enabled = true; Console.WriteLine(“Press \’q\’ to quit the sample.”); while(Console.Read() != ‘q’); } // Specify what you want to happen when the Elapsed event is raised. private static void OnTimedEvent(object source, ElapsedEventArgs e) { … Read more

ASP.NET MVC on IIS 7.5

ASP.NET 4 was not registered in IIS. Had to run the following command in the command line/run 32bit (x86) Windows %windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -ir 64bit (x64) Windows %windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -ir Note from David Murdoch’s comment: That the .net version has changed since this Answer was posted. Check which version of the framework is in the %windir%\Microsoft.NET\Framework64 directory and … Read more

What ‘additional configuration’ is necessary to reference a .NET 2.0 mixed mode assembly in a .NET 4.0 project?

In order to use a CLR 2.0 mixed mode assembly, you need to modify your App.Config file to include: <?xml version=”1.0″?><configuration> <startup useLegacyV2RuntimeActivationPolicy=”true”> <supportedRuntime version=”v4.0″ sku=”.NETFramework,Version=v4.0″/> </startup></configuration> The key is the useLegacyV2RuntimeActivationPolicy flag. This causes the CLR to use the latest version (4.0) to load your mixed mode assembly. Without this, it will not work. … Read more

How can I run PowerShell with the .NET 4 runtime?

The best solution I have found is in the blog post Using Newer Version(s) of .NET with PowerShell. This allows powershell.exe to run with .NET 4 assemblies. Simply modify (or create) $pshome\powershell.exe.config so that it contains the following: <?xml version=”1.0″?> <configuration> <startup useLegacyV2RuntimeActivationPolicy=”true”> <supportedRuntime version=”v4.0.30319″/> <supportedRuntime version=”v2.0.50727″/> </startup> </configuration> Additional, quick setup notes: Locations and … Read more

How to flatten tree via LINQ?

You can flatten a tree like this: IEnumerable<MyNode> Flatten(IEnumerable<MyNode> e) => e.SelectMany(c => Flatten(c.Elements)).Concat(new[] { e }); You can then filter by group using Where(…). To earn some “points for style”, convert Flatten to an extension function in a static class. public static IEnumerable<MyNode> Flatten(this IEnumerable<MyNode> e) => e.SelectMany(c => c.Elements.Flatten()).Concat(e); To earn more points … Read more