News In The Net40

1,258 views

Published on

These are the slides for the "News in Net4.0" presentation from 20th of feb 2010 in Iasi at Ramada (details at codecamp.ro)

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,258
On SlideShare
0
From Embeds
0
Number of Embeds
56
Actions
Shares
0
Downloads
14
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

News In The Net40

  1. 1. News in C# and NET 4.0<br />Iaşi, 20 februarie 2010<br />Florin Cardaşim, www.rms.ro<br />
  2. 2. Agenda<br />
  3. 3. C# 4 named and default params<br />Named method parameters<br />Default method parameter values<br />
  4. 4. C# 4 & DLR<br />Interop via Dynamic Language Runtime<br />Dynamically-Typed<br />Ruby<br />Python<br />Statically-Typed<br />VB<br />Dynamic Language Runtime<br />C#<br />Common Language Runtime<br />
  5. 5. C# 4 & the DLR: dynamic<br />Interop with dynamic languages like Ruby, Python<br />Interop with COM<br />
  6. 6. C# 4 – DLR Support: dynamic<br />Interop always comes<br /> with a performance cost, <br />so do not use dynamic if <br />you don’t really need it<br />
  7. 7. C# 4 – DLR Support: dynamic<br />Don’t abuse dynamic in C# because you loose:<br /><ul><li>compile time type checking and intellisense
  8. 8. runtime performance</li></ul>Use dynamic where appropriate<br />
  9. 9. C# 4 & the DLR<br />System.Numerics.BigInteger<br />System.Numerics.Complex<br />System.Tuples<br />Tuple.Create(1,2,3,4,5,6,7,8) - maximum 8 members!!<br />Property names are Item1, Item2, .., Item8 – ugly!<br />Can be used as method params and return values<br />Can be inherited<br />Can be extended by extension methods<br />Specifically useful in F#<br />I’ll probably NOT use it in C# <br />http://msdn.microsoft.com/en-us/vcsharp/ee957397.aspx<br />
  10. 10. Generics Covariance & Contravariance<br />
  11. 11. Generics Co&Contravariance<br />http://msdn.microsoft.com/en-us/library/dd799517(VS.100).aspx<br />
  12. 12. Exceptions Management<br />This code is bad!<br />WHY?!!!<br />
  13. 13. Exceptions Management<br /><ul><li>What is the problem?</li></ul>(Exception ex) might be a Corrupted State Exception (CSE) , like Access Violation, Invalid Memory, Divide By Zero, Stack Overflow<br /><ul><li>What to do if Exception is CSE?</li></ul>Your process and data are in danger. ABORT.<br />Are other actions possible?<br /><ul><li>What is CLR 4.0 doing?</li></ul>CLR 4.0 will NOT deliver CSEs to our code by default<br />catch(Exception ex) will NOT catch the CSE<br />Your process will ABORT<br />
  14. 14. Exceptions Management<br />For backwards compatibility use<br />Or at application level<br />
  15. 15. Exceptions Management<br />A bit of history:<br /><ul><li>CLR1.1: unhandled exceptions (on secondary threads) will NOT abort process
  16. 16. CLR 2.0: unhandled exception on secondary will ABORT the process
  17. 17. CLR 4.0: CSEs not handled by catch(Exception), process will ABORT</li></ul>Conclusions:<br /><ul><li>Do not handle exceptions if you don’t know how
  18. 18. ABORT is better than a corrupted process</li></li></ul><li>Exceptions Management<br />Conclusions:<br /><ul><li>Only catch exceptions that you can handle
  19. 19. ABORT is better than a corrupted process
  20. 20. If your process ABORTs than there is a bug somewhere. GO FIX IT!
  21. 21. If you really need CSEs in your code use: </li></ul>[HandleProcessCorruptedStateExceptions]<br />Or <br />legacyCorruptedStateExceptionsPolicy enabled="true“<br />
  22. 22. Net 4.0 application dump debugging<br />When do we need a dump<br />Crash, hang, performance analysis etc<br />How to collect a dump<br />adplus.vbs, DebugDiag etc<br />Task Manager/Create Dump File<br />VS2010/Debug/Save Dump As…<br />How to analyze the dump<br />Until now windbgonly for native apps<br />Now VS2010 knows to debug .NET 4.0 app dump<br />
  23. 23. Net 4.0 dump debugging<br />Dump debugging with WinDbg<br />
  24. 24. Net 4.0 dump debugging<br />
  25. 25. Code Contracts<br />Until CLR 4.0<br /><ul><li>Code comments
  26. 26. Debug.Assert, Argument validation: if-then-throw
  27. 27. Unit tests? </li></ul>In CLR 4.0 we have System.Diagnostics.Contracts<br /><ul><li>Preconditions
  28. 28. Required before a method can run
  29. 29. Postconditions
  30. 30. True at the completion of a method
  31. 31. Object invariants
  32. 32. Conditions that are always true</li></li></ul><li>App Domain Profiling<br /><ul><li>A host application may profile the activity of the hosted applications (for example add-ins) and attempt to restart it if takes too many resources</li></ul>DEMO: “MonitoringIsEnabled”<br />
  33. 33. Enhanced GC<br />Concurrent GC<br /><ul><li>Can NOT do Gen0, Gen1 GC (ephemeral segment) at the same time with Gen2 GC</li></li></ul><li>Enhanced GC <br />Backgound GC<br /><ul><li>CAN do a Gen0, Gen1 GC (ephemeral segment) while doing Gen2 GC</li></li></ul><li>Enhanced GC <br />Concurrent GC<br />Background GC<br />Latency during application execution<br />
  34. 34. Parallel Computing in .NET 4<br />Why should we care about parallel computing?<br />Because we care about application performance<br />Because our CPUs/cores are not used at full capacity<br />System.Threading<br /><ul><li> Barrier
  35. 35. CountdownEvent</li></ul>Parallel Extensions<br /><ul><li> Parallel LINQ (PLINQ)
  36. 36. Task Parallel Library (TPL)
  37. 37. Coordination Data Structures – System.Colllectiions.Concurrent</li></ul> Unified cancellation model<br /><ul><li>CancellationTokenSource, CancellationToken</li></li></ul><li>Demo: System.Threading, UCM<br />System.Threading<br /><ul><li> Barrier
  38. 38. CountdownEvent</li></ul>Parallel Extensions<br /><ul><li> Parallel LINQ (PLINQ)
  39. 39. Task Parallel Library (TPL)
  40. 40. Coordination Data Structures (CDS)</li></ul> Unified cancellation model<br /><ul><li>CancellationTokenSource, CancellationToken</li></li></ul><li>Demo: Parallel LINQ<br />System.Threading<br /><ul><li> Barrier
  41. 41. CountdownEvent</li></ul>Parallel Extensions<br /><ul><li> Parallel LINQ (PLINQ)
  42. 42. Task Parallel Library (TPL)
  43. 43. Coordination Data Structures (CDS)</li></ul> Unified cancellation model<br /><ul><li>CancellationTokenSource, CancellationToken</li></li></ul><li>Demo: Task Parallel Library<br />System.Threading<br /><ul><li> Barrier
  44. 44. CountdownEvent</li></ul>Parallel Extensions<br /><ul><li> Parallel LINQ (PLINQ)
  45. 45. Task Parallel Library (TPL)
  46. 46. Coordination Data Structures (CDS)</li></ul> Unified cancellation model<br /><ul><li>CancellationTokenSource, CancellationToken</li></li></ul><li>References<br />MSDN<br />MSDN Magazine<br />Channel9<br />VS2010 Training Kit<br />Msdn.blogs.com/Tess<br />
  47. 47. Please fill the evaluation form !!!<br />Thank you very much<br />Florin Cardasim<br /><ul><li>florin.cardasim@rms.ro
  48. 48. www.rms.ro
  49. 49. www.codecamp.ro
  50. 50. www.Twitter.com/cardasim</li>

×