News In The Net40
-
Upload
florin-cardasim -
Category
Technology
-
view
1.051 -
download
1
description
Transcript of News In The Net40
News in C# and NET 4.0
Iaşi, 20 februarie 2010
Florin Cardaşim, www.rms.ro
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#)
C# 4 named and default params Named method parameters Default method parameter values
C# 4 & DLR Interop via Dynamic Language Runtime
Common Language Runtime
Statically-Typed
C#
VB
RubyPython
Dynamically-Typed
Dynamic Language Runtime
C# 4 & the DLR: dynamic Interop with dynamic languages like Ruby,
Python
Interop with COM
C# 4 – DLR Support: dynamic
Interop always comes
with a performance cost,
so do not use dynamic if
you don’t really need it
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
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
Generics Covariance & Contravariance
Generics Co&Contravariance
http://msdn.microsoft.com/en-us/library/dd799517(VS.100).aspx
Exceptions Management This code is bad! WHY?!!!
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
Exceptions Management For backwards compatibility use
Or at application level
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
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“
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
Net 4.0 dump debugging
Dump debugging with WinDbg
Net 4.0 dump debugging
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
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”
Enhanced GC
Concurrent GC
• Can NOT do Gen0, Gen1 GC (ephemeral segment) at the same time with Gen2 GC
Enhanced GC
Backgound GC
• CAN do a Gen0, Gen1 GC (ephemeral segment) while doing Gen2 GC
Enhanced GC Concurrent GC
Background GC
Latency during application execution
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
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)
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)
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)
References
MSDN MSDN Magazine Channel9 VS2010 Training Kit Msdn.blogs.com/Tess
Please fill the evaluation form !!!
Thank you very much
Florin Cardasim• [email protected]• www.rms.ro• www.codecamp.ro• www.Twitter.com/cardasim