news in the net40
DESCRIPTION
These are the slides for the "News in Net4.0" presentation from 20th of feb 2010 in Iasi at Ramada (details at codecamp.ro)TRANSCRIPT
![Page 1: News In The Net40](https://reader035.vdocuments.site/reader035/viewer/2022081602/555109c6b4c90501448b5663/html5/thumbnails/1.jpg)
News in C# and NET 4.0
Iaşi, 20 februarie 2010
Florin Cardaşim, www.rms.ro
![Page 2: News In The Net40](https://reader035.vdocuments.site/reader035/viewer/2022081602/555109c6b4c90501448b5663/html5/thumbnails/2.jpg)
Agenda
News that we’ll cover today
• Core• C# named & default params• DLR: dynamic, BigInteger, Tuple• Generics co&contra-variance• Corrupted State Exceptions• Dump debugging with VS2010• Code contracts• App Domain profiling• Garbage collector enhancements• Parallel Computing
• Workflow Foundation• Communication Foundation• ASP.NET 4.0 MVC• Visual Studio 2010
News for you to explore
• Improved security model• Application compatibility and
deployment• Networking• Web - ASP.NET4.0• Client• Data
• ADO.NET• Dynamic Data
• Programming languages (C++,VB, F#)
![Page 3: News In The Net40](https://reader035.vdocuments.site/reader035/viewer/2022081602/555109c6b4c90501448b5663/html5/thumbnails/3.jpg)
C# 4 named and default params Named method parameters Default method parameter values
![Page 4: News In The Net40](https://reader035.vdocuments.site/reader035/viewer/2022081602/555109c6b4c90501448b5663/html5/thumbnails/4.jpg)
C# 4 & DLR Interop via Dynamic Language Runtime
Common Language Runtime
Statically-Typed
C#
VB
RubyPython
Dynamically-Typed
Dynamic Language Runtime
![Page 5: News In The Net40](https://reader035.vdocuments.site/reader035/viewer/2022081602/555109c6b4c90501448b5663/html5/thumbnails/5.jpg)
C# 4 & the DLR: dynamic Interop with dynamic languages like Ruby,
Python
Interop with COM
![Page 6: News In The Net40](https://reader035.vdocuments.site/reader035/viewer/2022081602/555109c6b4c90501448b5663/html5/thumbnails/6.jpg)
C# 4 – DLR Support: dynamic
Interop always comes
with a performance cost,
so do not use dynamic if
you don’t really need it
![Page 7: News In The Net40](https://reader035.vdocuments.site/reader035/viewer/2022081602/555109c6b4c90501448b5663/html5/thumbnails/7.jpg)
C# 4 – DLR Support: dynamic Don’t abuse dynamic in C# because you loose:
• compile time type checking and intellisense• runtime performance
Use dynamic where appropriate
![Page 8: News In The Net40](https://reader035.vdocuments.site/reader035/viewer/2022081602/555109c6b4c90501448b5663/html5/thumbnails/8.jpg)
C# 4 & the DLR
System.Numerics.BigInteger System.Numerics.Complex System.Tuples
Tuple.Create(1,2,3,4,5,6,7,8) - maximum 8 members!! Property names are Item1, Item2, .., Item8 – ugly! Can be used as method params and return values Can be inherited Can be extended by extension methods Specifically useful in F# I’ll probably NOT use it in C# http://msdn.microsoft.com/en-us/vcsharp/
ee957397.aspx
![Page 9: News In The Net40](https://reader035.vdocuments.site/reader035/viewer/2022081602/555109c6b4c90501448b5663/html5/thumbnails/9.jpg)
Generics Covariance & Contravariance
![Page 10: News In The Net40](https://reader035.vdocuments.site/reader035/viewer/2022081602/555109c6b4c90501448b5663/html5/thumbnails/10.jpg)
Generics Co&Contravariance
http://msdn.microsoft.com/en-us/library/dd799517(VS.100).aspx
![Page 11: News In The Net40](https://reader035.vdocuments.site/reader035/viewer/2022081602/555109c6b4c90501448b5663/html5/thumbnails/11.jpg)
Exceptions Management This code is bad! WHY?!!!
![Page 12: News In The Net40](https://reader035.vdocuments.site/reader035/viewer/2022081602/555109c6b4c90501448b5663/html5/thumbnails/12.jpg)
Exceptions Management
• What is the problem? (Exception ex) might be a Corrupted State Exception (CSE) ,
like Access Violation, Invalid Memory, Divide By Zero, Stack Overflow
• What to do if Exception is CSE? Your process and data are in danger. ABORT. Are other actions possible?
• What is CLR 4.0 doing? CLR 4.0 will NOT deliver CSEs to our code by default catch(Exception ex) will NOT catch the CSE Your process will ABORT
![Page 13: News In The Net40](https://reader035.vdocuments.site/reader035/viewer/2022081602/555109c6b4c90501448b5663/html5/thumbnails/13.jpg)
Exceptions Management For backwards compatibility use
Or at application level
![Page 14: News In The Net40](https://reader035.vdocuments.site/reader035/viewer/2022081602/555109c6b4c90501448b5663/html5/thumbnails/14.jpg)
Exceptions Management A bit of history:
• CLR1.1: unhandled exceptions (on secondary threads) will NOT abort process
• CLR 2.0: unhandled exception on secondary will ABORT the process
• CLR 4.0: CSEs not handled by catch(Exception), process will ABORT
Conclusions:• Do not handle exceptions if you don’t know how• ABORT is better than a corrupted process
![Page 15: News In The Net40](https://reader035.vdocuments.site/reader035/viewer/2022081602/555109c6b4c90501448b5663/html5/thumbnails/15.jpg)
Exceptions Management Conclusions:
• Only catch exceptions that you can handle• ABORT is better than a corrupted process• If your process ABORTs than there is a bug
somewhere. GO FIX IT!• If you really need CSEs in your code use:
[HandleProcessCorruptedStateExceptions]Or
legacyCorruptedStateExceptionsPolicy enabled="true“
![Page 16: News In The Net40](https://reader035.vdocuments.site/reader035/viewer/2022081602/555109c6b4c90501448b5663/html5/thumbnails/16.jpg)
Net 4.0 application dump debugging When do we need a dump
Crash, hang, performance analysis etc
How to collect a dump adplus.vbs, DebugDiag etc Task Manager/Create Dump File VS2010/Debug/Save Dump As…
How to analyze the dump Until now windbg only for native apps Now VS2010 knows to debug .NET 4.0 app dump
![Page 17: News In The Net40](https://reader035.vdocuments.site/reader035/viewer/2022081602/555109c6b4c90501448b5663/html5/thumbnails/17.jpg)
Net 4.0 dump debugging
Dump debugging with WinDbg
![Page 18: News In The Net40](https://reader035.vdocuments.site/reader035/viewer/2022081602/555109c6b4c90501448b5663/html5/thumbnails/18.jpg)
Net 4.0 dump debugging
![Page 19: News In The Net40](https://reader035.vdocuments.site/reader035/viewer/2022081602/555109c6b4c90501448b5663/html5/thumbnails/19.jpg)
Code Contracts Until CLR 4.0
• Code comments• Debug.Assert, Argument validation: if-then-throw• Unit tests?
In CLR 4.0 we have System.Diagnostics.Contracts• Preconditions
• Required before a method can run
• Postconditions• True at the completion of a method
• Object invariants• Conditions that are always true
![Page 20: News In The Net40](https://reader035.vdocuments.site/reader035/viewer/2022081602/555109c6b4c90501448b5663/html5/thumbnails/20.jpg)
App Domain Profiling
• 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
DEMO: “MonitoringIsEnabled”
![Page 21: News In The Net40](https://reader035.vdocuments.site/reader035/viewer/2022081602/555109c6b4c90501448b5663/html5/thumbnails/21.jpg)
Enhanced GC
Concurrent GC
• Can NOT do Gen0, Gen1 GC (ephemeral segment) at the same time with Gen2 GC
![Page 22: News In The Net40](https://reader035.vdocuments.site/reader035/viewer/2022081602/555109c6b4c90501448b5663/html5/thumbnails/22.jpg)
Enhanced GC
Backgound GC
• CAN do a Gen0, Gen1 GC (ephemeral segment) while doing Gen2 GC
![Page 23: News In The Net40](https://reader035.vdocuments.site/reader035/viewer/2022081602/555109c6b4c90501448b5663/html5/thumbnails/23.jpg)
Enhanced GC Concurrent GC
Background GC
Latency during application execution
![Page 24: News In The Net40](https://reader035.vdocuments.site/reader035/viewer/2022081602/555109c6b4c90501448b5663/html5/thumbnails/24.jpg)
Parallel Computing in .NET 4 Why should we care about parallel computing?
Because we care about application performance Because our CPUs/cores are not used at full capacity
Unified cancellation model• CancellationTokenSource, CancellationToken
System.Threading• Barrier• CountdownEvent
Parallel Extensions• Parallel LINQ (PLINQ)• Task Parallel Library (TPL)•Coordination Data Structures – System.Colllectiions.Concurrent
![Page 25: News In The Net40](https://reader035.vdocuments.site/reader035/viewer/2022081602/555109c6b4c90501448b5663/html5/thumbnails/25.jpg)
Demo: System.Threading, UCM
Unified cancellation model• CancellationTokenSource, CancellationToken
System.Threading
• Barrier• CountdownEvent
Parallel Extensions• Parallel LINQ (PLINQ)• Task Parallel Library (TPL)•Coordination Data Structures (CDS)
![Page 26: News In The Net40](https://reader035.vdocuments.site/reader035/viewer/2022081602/555109c6b4c90501448b5663/html5/thumbnails/26.jpg)
Demo: Parallel LINQ
Unified cancellation model• CancellationTokenSource, CancellationToken
System.Threading
• Barrier• CountdownEvent
Parallel Extensions• Parallel LINQ (PLINQ)• Task Parallel Library (TPL)•Coordination Data Structures (CDS)
![Page 27: News In The Net40](https://reader035.vdocuments.site/reader035/viewer/2022081602/555109c6b4c90501448b5663/html5/thumbnails/27.jpg)
Demo: Task Parallel Library
Unified cancellation model• CancellationTokenSource, CancellationToken
System.Threading
• Barrier• CountdownEvent
Parallel Extensions• Parallel LINQ (PLINQ)• Task Parallel Library (TPL)•Coordination Data Structures (CDS)
![Page 28: News In The Net40](https://reader035.vdocuments.site/reader035/viewer/2022081602/555109c6b4c90501448b5663/html5/thumbnails/28.jpg)
References
MSDN MSDN Magazine Channel9 VS2010 Training Kit Msdn.blogs.com/Tess
![Page 29: News In The Net40](https://reader035.vdocuments.site/reader035/viewer/2022081602/555109c6b4c90501448b5663/html5/thumbnails/29.jpg)
Please fill the evaluation form !!!
Thank you very much
Florin Cardasim• [email protected]• www.rms.ro• www.codecamp.ro• www.Twitter.com/cardasim