Presentation is loading. Please wait.

Presentation is loading. Please wait.

C# 5.0 Alex Davies 22 nd December 2011. What we will cover C# 5.0,.NET 4.5, Visual Studio 11 Caller Info Attributes Upgrade from synchronous to asynchronous.

Similar presentations


Presentation on theme: "C# 5.0 Alex Davies 22 nd December 2011. What we will cover C# 5.0,.NET 4.5, Visual Studio 11 Caller Info Attributes Upgrade from synchronous to asynchronous."— Presentation transcript:

1 C# 5.0 Alex Davies 22 nd December 2011

2 What we will cover C# 5.0,.NET 4.5, Visual Studio 11 Caller Info Attributes Upgrade from synchronous to asynchronous Catching the asynchronous error Performance tuning Roslyn Pizza

3 A Note on Versions C# Version.NET VersionDevelopment Environment 1.0 Visual Studio.NET 2002 1.21.1Visual Studio.NET 2003 2.0 Visual Studio 2005 3.02.0, 3.0, 3.5Visual Studio 2008 4.0 Visual Studio 2010 5.04.5Visual Studio 11 Developer preview

4 What’s in C# 5.0 Caller Info Attributes Asynchronous Programming Model Roslyn - Compiler as a Service (sort of)

5 Caller Info Attributes Injects information about the methods caller into parameters Not in developer preview public static void Log(string message, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0, [CallerMemberName] string member = "") { Console.WriteLine("{0}:{1} – {2}: {3}", file, line, member, message); }

6 Asynchronous Programming Traditionally applications would stall on blocking IO async / await prevents blocking First part of the method runs synchronously await saves state returns the current method. When awaited task finishes the rest of the method is scheduled to run await must be within an async method

7 Error Handling Exceptions are thrown on await (even if thrown in the synchronous part of the code) If it is an async void method, unhandled exception is thrown If you never await a task two options –Hide the error (this is default) –Throw an unhandled exception next time GC runs Can listen and handle exceptions on the TaskSchedular.UnobservedTaskExceptions event

8 Squeezing out the performance Async methods are not normal methods Task.ConfigureAwait(continueOnCaptured Context:true); does not bother about continuing on same thread Compiler optimizes for complete tasks Cache completed tasks rather than caching data

9 Roslyn – Compiler as a Service Not really part of C# 5.0, but closely related Currently in CTP Offers better interaction with the compiler, allowing access to syntax trees, symbol tables and all other compiler internals Allows for easy to use scripting var engine = new ScriptEngine(); engine.Execute(@"System.Console.WriteLine(""Hello Roslyn"");"); var engine = new ScriptEngine(); engine.Execute( @"System.Console.WriteLine(""Dynamic Code is Great"");“ );

10 Summary Slide Caller Info Attributes to get meta information C# 5.0 is really all about async Two new keywords allow writing asynchronous code in a synchronous style Take care of errors, need to know what can and can’t be caught Roslyn for dynamic code generation


Download ppt "C# 5.0 Alex Davies 22 nd December 2011. What we will cover C# 5.0,.NET 4.5, Visual Studio 11 Caller Info Attributes Upgrade from synchronous to asynchronous."

Similar presentations


Ads by Google