Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Core .NET Framework 4.0 Enhancements

2,445 views

Published on

  • Be the first to comment

Core .NET Framework 4.0 Enhancements

  1. 1. Core .NET Framework 4 Enhancements<br />
  2. 2. Your presenter for today?<br />Robert MacLean<br />sadev.co.za<br />@rmaclean<br />
  3. 3. What to expect<br />
  4. 4. What are we covering?<br />LINQ<br />ASP.NET<br />WCF<br />WPF<br />ADO.NET<br />…<br />C#<br />VB.NET<br />C++<br />DLR<br />Base Class Libraries<br />Common Language Runtime<br />JITNGEN<br />Garbage Collector<br />Type System<br />Exception handling<br />Hosting APIs<br />Loader and binder<br />Debugging, …<br />
  5. 5. PREP <br />VS – with base project<br />Open program.cs<br />VS – With SxS Demo<br />VS – With Movies (MEF) demo, do a build and remove some of the adapters from the output (put somewhere you can get them easily). Keep folder open<br />VS – With location demo.<br />Clean reflector<br />
  6. 6. BIG INT<br />Tour base<br />[Ctrl+1] – talk about the big number and what happens when you try to go over it (overflow and exceptions). Point out decimal is a type value.<br />decimal bigNumber = decimal.MaxValue;<br />Console.WriteLine(bigNumber);<br />bigNumber++;<br />Console.WriteLine(bigNumber);<br />Add reference to system.numerics (nice to point out performance of add reference dialog)<br />[Ctrl+2] – change to big int. point out it is a class. Talk about static methods needed. Talk about no logical upperlimit<br />BigIntegerbigInteger1 = new BigInteger(decimal.MaxValue);<br />Console.WriteLine(bigInteger1);<br />BigInteger bigInteger2 = new BigInteger(decimal.MaxValue);<br />Console.WriteLine(bigInteger1 * bigInteger2);<br />Console.WriteLine(BigInteger.Multiply(bigInteger1, bigInteger2));<br />LAZY<T><br />[Ctrl+3] Add the slow class<br />[Ctrl+4] Add code to the main method to show the constructor is slow<br />Console.WriteLine("Before slow create");<br />Slow slow = new Slow();<br />Console.WriteLine("After slow create");<br />slow.Message();<br />[Ctrl+5] Now change to implement Lazy<T> and show how it is not created until we actually use it.<br />Console.WriteLine("Before slow create");<br />Lazy<Slow> slow = new Lazy<Slow>();<br />Console.WriteLine("After slow create");<br />Console.WriteLine(slow.IsValueCreated); <br />slow.Value.Message();<br />Console.WriteLine(slow.IsValueCreated); <br />Remove the main method and type sorted – nice to show intellisense filtering. Should have sortedlist, sorteddictionary and sortedset<br />Talk about difference between sorting in a list which needs to check during actions and unbalanced binary tree which takes no perf hit on insert etc… and still gives great sorting perf. Also point out difference in requirements of keys for list/dictionary and objects in set. <br />
  7. 7. IObserable<br />SLIDE (1) – explain the pattern<br />[Ctrl+6] Add data class <br />[Ctrl+7] Add the provider class<br />[Ctrl+8] Add the subscriber class<br />[Ctrl+9] Add the code to the main method<br />GPSSensor sensor = new GPSSensor();<br />Map map = new Map();<br />sensor.Subscribe(map, ConsoleColor.Red);<br />//Map map2 = new Map();<br />//sensor.Subscribe(map2, ConsoleColor.Yellow);<br />do<br />{<br />sensor.GetPosition();<br />Thread.Sleep(1000);<br />} while (map.StillTracking);<br />Uncomment to show second subscriber<br />SxS<br />Slide (1) – Explain the issue<br />Switch to VS with loader demo.<br />Tour the code<br />start with the two assemblies, point out versions they are compiled to and what they do.<br />Now show the Loader app and show the version (3.5).<br />Show the code and point out that with reflection we are loading it – remind the audience to remember this stuff for later<br />Run the app and note it points out v2 NOT 3.5 – cause the CLR hasn’t changed since 2.<br />Click the run 3.5 assembly – works. Click run 4 assembly and note the exception.<br />Now change the assembly version of loader to 4. and do stesp 4 and 5 again and it works!<br />PIA<br />Slide(1) – Explain what PIA is. Problems – rediretibution and size of distributable<br />Go to VS<br />[ALT +1 ] Add the count down method<br />private static void CountDown()<br /> {<br />Console.WriteLine("3...");<br />Thread.Sleep(1000);<br />Console.WriteLine("2...");<br />Thread.Sleep(1000);<br />Console.WriteLine("1...");<br />Thread.Sleep(1000);<br />}<br />
  8. 8. Add reference to Microsoft.Office.Interop.Excel – add version 14. <br />Properties of the assembly and make sure embed is off.<br />[ALT + 3] Add code to main method and talk through. Since it is automation explain the count down. Run and move back.<br />Go to binary and drag into reflector – point out that it is listed under references which means shipping it.<br />Go back to VS and change the assembly to embed. Build and demo to show it still works. Refresh reflector and show it has moved from references to actually embedding it into the project.<br />Code Contracts<br />[ALT + 4] Show the code and explain how the zune works out dates. <br />[ALT + 5] Add code to call it in the main<br />intdayInYear;<br />intyear = ZuneDate.YearSince1980(300, out dayInYear);<br />Console.WriteLine("It's the {0} day of {1}", dayInYear, year);<br />Now change day to: 10593 and explain the bugon Dec 31 2008<br />[ALT + 6] – fully updated loop<br />Add to start of loop: intdaysAtStart = daysLeft;<br />Add to end of loop: Contract.Assert(daysLeft < daysAtStart);<br />Now project and enable static code contract checking and build<br />Point out the unproven issue – saying it thinks that there is a scenario that could fail<br />[ALT + 7] Add the else to verify and build<br />else<br />{<br />Contract.Assert(false);<br />}<br />It is the problem – so lets deal with it<br />[ALT +8] Change the else contents to then build and show no errors. Now show <br />dayInYear= 366;<br /> return year;<br />Change day to -1 and show it doesn’t make sense.<br />[ALT+9] Add to start of check: Contract.Requires(daysSince1980 > 0);<br />Build and show how it identifies it – that is preconditions. Leave for now.<br />[Ctrl+Alt+1] Add post conditions:<br />Contract.Ensures(Contract.ValueAtReturn<int>(out dayInYear) > 0);<br />Contract.Ensures(Contract.ValueAtReturn<int>(out dayInYear) < 367);<br />Run and show that the code doesn’t fail even though our condition is not enforces the check. Pop into reflector and show that those conditions aren’t there.<br />Turn on runtime checking and build and run – not the failure. Pop into reflector and show the code now and show the new code which has been added to the start and end! <br />Mention sandcastle documentation tool support too<br />
  9. 9. MEF<br />Show folder with Movies project in it and run it. <br />Add in the files we removed during the setup and run again. Remind people of reflection we saw before.<br />Switch to VS with Movies Project and tour the code/<br />Explain we have an interface <br />Show a provider implements it and is attributed with export.<br />Show code of form and show the ImportMany attribute and talk about the initialisation (Catalog, container, and then we can loop over it).<br />Parallel<br />Open Task Manager<br />Slides (1) – explain enhancements in parallel and why it is important<br />Show hunt button code and explain that change it [Ctrl+Alt+2]<br />Parallel.ForEach(movieProviders, movieProvider =><br /> {<br />HighlightProvider(movieProvider, HighlightState.Searching);<br />IEnumerable<MovieInfo> movies = movieProvider.Search(MovieNameTextBox.Text);<br />HighlightProvider(movieProvider, HighlightState.Loading);<br />AddRange(results, movies);<br />HighlightProvider(movieProvider, HighlightState.None);<br />});<br />Run and show in parallel<br />Go to IMDB provider and show the LINQ query and explain that could also be parallele.<br />[CTRL+ALT+3]: varmatchedLines = from l in File.ReadLines("movies.list").AsParallel()<br />Build and show improvement (if any)<br />Location<br />Switch to location demo and tour that code and demo. PRAY<br />
  10. 10. All the small things<br /><demo/><br />
  11. 11. IObservable<br />Update<br />Publisher<br />Data<br />Data<br />Data<br />Subscriber<br />Subscriber<br />Subscriber<br />
  12. 12. IObservable<br /><demo/><br />
  13. 13. In-process side-by-side (SxS)<br />2.0 addin<br />3.0 addin<br />3.5 addin<br />4.0 addin<br />.NET 4.0<br />.NET 3.5<br />.NET 3.0<br />.NET 2.0<br />Host Process (eg: Outlook)<br />
  14. 14. In Process SxS<br /><demo/><br />
  15. 15. Primary Interop Assemblies (PIA)<br />.NET<br />Meta Data<br />(Headers)<br />PIA<br />COM<br />Helper classes<br />
  16. 16. PIA<br /><demo/><br />
  17. 17. Tour of .NET 4<br />Part 2<br /><demo/><br />
  18. 18. Parallel<br />PLINQ<br />Task Parallel Library<br />.NET Framework<br />ThreadPool<br />Thread<br />OS<br />
  19. 19. Parallel Enhancements<br /><demo/><br />
  20. 20. System.Device.Location<br /><demo/><br />
  21. 21. Location<br />Windows 7 only<br />Status will be Disabled for other platforms<br />Geosense for Windows<br />http://geosenseforwindows.com/<br />
  22. 22. Is this everything?<br />Support for Teredo<br />All the new security enhancements in networking<br />Garbage Collection Improved<br />New ways to detect 64bit OS’s and processes<br />Improvements to System.Enviroment<br />Ngen Improved<br />Memory Mapped Files<br />New File and Directory Enumeration options based on generics<br />Tuples<br />F#<br />New options for performance monitoring which are not invasive<br />Improved parsing for GUID<br />New helper method for Thread<br />Improvements for Registries<br />New helper method for Monitors<br />Better stream compression options<br />New helper methods for UIntPtr and IntPtr<br />New helper method for System.IO.Path<br />New helper method for Streams<br />New helper method and parsing options for Enum<br />New helper method for StopWatch<br />New helper method for StringBuilder<br />System.Numerics.Complex<br />TimeSpanParsing Improvements<br />String Improvements<br />
  23. 23. Future?<br />http://bcl.codeplex.com<br />BigRational<br />LongPath<br />PerfMonitor<br />TraceEvent<br />
  24. 24. Questions and Answers<br />Reminder:<br />www.sadev.co.za<br /><questions/><br />
  25. 25. We Want To Hear From You!<br />Connect with Microsoft South Africa's Developer & Platform Group<br />blogs.msdn.com/southafrica<br />twitter.com/msdevsa<br />Microsoft DevsSA<br />Required Slide<br />
  26. 26. Required Slide<br />Win a Wireless Entertainment Desktop 8000!<br />Complete your evaluation and enter to win!<br />
  27. 27. Submit an Entry Form at the BB&D Stand and Win*!A Dell Netbook valued at R4,000<br />* Terms & conditions apply<br />
  28. 28. © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.<br />The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.<br />

×