350 likes | 552 Views
What’s New in .NET 4?. Pavel Yosifovich CTO, Matrix Global pavely@matrix-global.net http://blogs.microsoft.co.il/blogs/pavely. Agenda. Introduction What’s new in CLR 4? What’s new in BCL 4? Q & A Summary Related Links. Introduction. .NET Evolution. What Is The .NET Framework?. WPF.
E N D
What’s New in .NET 4? Pavel Yosifovich CTO, Matrix Global pavely@matrix-global.net http://blogs.microsoft.co.il/blogs/pavely
Agenda • Introduction • What’s new in CLR 4? • What’s new in BCL 4? • Q & A • Summary • Related Links
Introduction • .NET Evolution
What Is The .NET Framework? WPF Win Forms DLR ASP.NET WCF LINQ And more! Base Class Libraries The CLR JIT & NGEN Garbage Collector Security Model Exception Handling Loader & Binder
.NET Framework 4.0 User Interface Data Access Services ASP.NET (WebForms, MVC, Dynamic Data) Windows Presentation Foundation ADO.NET Entity Framework Data Services Windows Communication Foundation WinForms LINQ to SQL Windows Workflow Foundation AppFacbric Core Dynamic Language Runtime Base Class Library Languages Parallel Extensions Managed Extensibility Framework LINQ Common Language Runtime
What’s New in CLR 4? • Side by side hosting • Type embedding (“No PIA”) • Background GC • AppDomain Monitoring
Why High Compatibility Is So Hard • .NET Framework 1.1 was highly compatible with .NET 1.0 • What’s wrong with this code? • Thread[] threads = new Thread[8]; • for (int i = 0; i < 8; i++) { • Worker worker = new Worker(); • threads[i] = new ThreadStart(worker.Work); • threads[i].Start(); • worker.identity = i; • } Code from an Outlook add-in Microsoft executives used
Existing Side-By-Side (SxS) 1.1 add-in 2.0 add-in 3.0 add-in 3.5 add-in 3.5 .NET 1.1 3.0 .NET 2.0 Host Process (e.g. Outlook)
In-Process Side-By-Side (SxS) 2.0 add-in 3.0 add-in 3.5 add-in 4.0 add-in 3.5 .NET 4.0 3.0 .NET 2.0 Host Process (e.g. Outlook)
Type Embedding • Problem • Using a COM component generates an interop assembly • Registered as Primary Interop Assembly (PIA) • Must “carry around” that PIA • Actual code may use just a fraction of the PIA
Type Embedding • Solution • Embed the actual interfaces and structs used in the client assembly • Can only work if those types can be considered equivalent by the CLR • CLR 4 introduces “Type Equivalence”
GC Recap – Pre CLR 4 GC Workstation Server Concurrent Collections “Normal”
GC in CLR 4 GC Workstation Server Concurrent Collections Background GC “Normal”
CLR 4 Garbage Collection Ephemeral Segment Other Segments • Workstation GC: Background GC • Can do Gen 0 & 1 GC while doing Gen 2 GC • Replaces Concurrent GC • Server GC • Nothing is changed (full GC notifications) Generation 0, 1 and parts of Generation 2 live here Most of Generation 2 lives here
AppDomain Monitoring • Host applications can monitor resource consumption of AppDomains • Set a (one time) global flag • Possible usage • Unloading resource hogging AppDomains • Comparing resource consumption of different algorithms
What’s New in the BCL? • Managed Extensibility Framework (MEF) • Code Contracts • System.IO Improvements • Memory Mapped Files • Task Parallel Library
Managed Extensibility Framework (MEF) • Open/Closed Principle • Software entities should be open for extensionbut closed for modification • The Managed Extensibility Framework enables greater (and easier) reuse of components • Applications can make the shift from being statically compiled to dynamically composed
Parts public class SimpleMortgageCalculator : IMortgageCalculator { public ILogger Logger { get; set; } public float Calculate() { Logger.Log("Calculating Mortgage"); return ...; } } Part A
Export it… [Export(typeof(IMortgageCalculator))] public class SimpleMortgageCalculator : IMortgageCalculator { public ILogger Logger { get; set; } public float Calculate() { Logger.Log("Calculating Mortgage"); return ...; } } Part A
Import it… [Export(typeof(IMortgageCalculator))] public class SimpleMortgageCalculator : IMortgageCalculator { [Import(typeof(ILogger))] public ILogger Logger { get; set; } public float Calculate() { Logger.Log("Calculating Mortgage"); return ...; } } Part A
Composeit. Catalogs provide the parts. Catalog
Composeit. Containeris the matchmaker. Catalog
Composeit. AggregatingCatalog Containeris the matchmaker. DirectoryCatalog AssemblyCatalog Catalog TypeCatalog
Code Contracts • Code Contracts are a way to specify contractual information that is not represented by a method signature alone • Runtime and/or compile time • A contract contains • Pre-conditions • Must be true before • Post-conditions • Must be true after • Objectinvariants • Must always hold true
Code Contracts Tools • CCRewrite.exe • IL injection • CCCheck.exe • Static verification • CCRefGen.exe • Contract reference assembly • CCDocGen.exe • XML documentation
System.IO Improvements • Methods returning collections instead of arrays • “deferred” LINQ style • Directory.EnumerateFiles, DirectoryEnumerateDirectories, File.ReadLines, File.WriteAllLines • DirectoryInfo.EnumerateDirectories, DirectoryInfo.EnumerateFiles • Enables efficient LINQ queries
Memory Mapped Files • In System.IO.MemoryMappedFiles • Allow sharing of memory between processes • Backed up by a specific file or the paging file • Can create large shared memory (more than 4GB) • Accessed using logical “Views” • Obtained as a stream (either “normal” or random access)
Task Parallel Library • Parallelism is a key trend • Availability of multi-core processors • Task parallel library • High level “threading” model • Parallel Extensions • Higher level abstractions • Parallel LINQ • Automatically parallelize LINQ queries
Related Links • Code Contracts http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx • MEF on CodePlex http://www.codeplex.com/MEF • CLR Team Blog http://blogs.msdn.com/clrteam/ • My blog http://blogs.microsoft.co.il/blogs/pavely