1 / 35

What’s New in .NET 4?

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.

johana
Download Presentation

What’s New in .NET 4?

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. What’s New in .NET 4? Pavel Yosifovich CTO, Matrix Global pavely@matrix-global.net http://blogs.microsoft.co.il/blogs/pavely

  2. Agenda • Introduction • What’s new in CLR 4? • What’s new in BCL 4? • Q & A • Summary • Related Links

  3. Introduction • .NET Evolution

  4. 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

  5. .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

  6. What’s New in CLR 4? • Side by side hosting • Type embedding (“No PIA”) • Background GC • AppDomain Monitoring

  7. 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

  8. 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)

  9. 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)

  10. 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

  11. 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”

  12. Type Embedding (“No PIA”)

  13. GC Recap – Pre CLR 4 GC Workstation Server Concurrent Collections “Normal”

  14. GC in CLR 4 GC Workstation Server Concurrent Collections Background GC “Normal”

  15. 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

  16. 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

  17. AppDomain Monitoring

  18. What’s New in the BCL? • Managed Extensibility Framework (MEF) • Code Contracts • System.IO Improvements • Memory Mapped Files • Task Parallel Library

  19. 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

  20. Parts public class SimpleMortgageCalculator : IMortgageCalculator { public ILogger Logger { get; set; } public float Calculate() { Logger.Log("Calculating Mortgage"); return ...; } } Part A

  21. Export it… [Export(typeof(IMortgageCalculator))] public class SimpleMortgageCalculator : IMortgageCalculator { public ILogger Logger { get; set; } public float Calculate() { Logger.Log("Calculating Mortgage"); return ...; } } Part A

  22. 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

  23. Composeit. Catalogs provide the parts. Catalog

  24. Composeit. Containeris the matchmaker. Catalog

  25. Composeit. AggregatingCatalog Containeris the matchmaker. DirectoryCatalog AssemblyCatalog Catalog TypeCatalog

  26. Managed Extensibility Framework

  27. 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

  28. Code Contracts

  29. Code Contracts Tools • CCRewrite.exe • IL injection • CCCheck.exe • Static verification • CCRefGen.exe • Contract reference assembly • CCDocGen.exe • XML documentation

  30. 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

  31. 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)

  32. Memory Mapped Files

  33. 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

  34. Parallel Extensions

  35. 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

More Related