31
NOME DA APRESENTAÇÃO Nome (Nick no Fórum) 25 DE MAIO @MICROSOFT What’s New In C# 5.0 Paulo Morgado (paulo.morgado)

What's New In C# 5.0 - Programar 2013

Embed Size (px)

DESCRIPTION

O novo paradigma de aplicações com ligação à nuvem leva a que a latência das comunicações seja maior do que aplicações totalmente locais. Para auxiliar o desenvolvimento deste novo paradigma, a última versão do C# 5.0 faz com que programação assíncrona pareça tão fácil como a programação síncrona.

Citation preview

Page 1: What's New In C# 5.0 - Programar 2013

NOME DA APRESENTAÇÃO Nome (Nick no Fórum)

25 DE MAIO @MICROSOFT

What’s New In C# 5.0Paulo Morgado (paulo.morgado)

Page 3: What's New In C# 5.0 - Programar 2013

A Language For Each Generation

# 3

Fortran, Cobol Basic, C, AsmVB, C++, Java, C# Async

1960Mainframe

1980Microcomputer

1990Desktop

2010Distributed

Page 4: What's New In C# 5.0 - Programar 2013

The Evolution Of C#

# 4

C# 1.0 C# 2.0 C# 3.0 C# 4.0 C# 5.0

Managed Generics LINQ Dynamic Async

Page 5: What's New In C# 5.0 - Programar 2013

The Evolution Of C#

# 5

C# 1.0 C# 2.0 C# 3.0 C# 4.0 C# 5.0

Managed Generics LINQ Dynamic Async

please wait for the next slideclicking won’t make it come any faster

Page 6: What's New In C# 5.0 - Programar 2013

DEMOSynchronous UI Application

Page 7: What's New In C# 5.0 - Programar 2013

Introducing Async

Page 8: What's New In C# 5.0 - Programar 2013

Introducing Async - Yesterday

# 8

Click

void LoadImage(){ // ... LoadLocalData(...); // ...}

void Button_Click(...){ LoadImage(); UpdateView();}

Click

Mes

sage

pum

p

Page 9: What's New In C# 5.0 - Programar 2013

Introducing Async - Today

# 9

Click

void LoadImage(){ // ... DownloadRemoteData(...); // ...}

void Button_Click(...){ LoadImage(); UpdateView();}

Click

Mes

sage

pum

p

Page 10: What's New In C# 5.0 - Programar 2013

DEMOAdd the async & await keywords

Page 11: What's New In C# 5.0 - Programar 2013

Introducing Async

async void Button_Click(...){ await LoadImageAsync(); UpdateView();}

async Task LoadImageAsync(){ // ... await DownloadRemoteDataAsync(...); // ...}

Mes

sage

pum

p

void LoadImage(){ // ... DownloadRemoteData(...); // ...}

void Button_Click(...){ LoadImage(); UpdateView();}

Click

Page 12: What's New In C# 5.0 - Programar 2013

Introducing Async

# 12

Click

async Task LoadImageAsync(){ // ... await DownloadRemoteDataAsync(...); // ...}

async void Button_Click(...){ await LoadImageAsync(); UpdateView();}

Click

Mes

sage

pum

p

Task ...DownloadRemoteDataAsync

Task ...LoadImageAsync

Download

LoadImage

Page 13: What's New In C# 5.0 - Programar 2013

DEMOAsync UI app: re-entrancy and deadlock

Page 14: What's New In C# 5.0 - Programar 2013

DEMOAsync with cancelation

Page 15: What's New In C# 5.0 - Programar 2013

DEMOAsync console app

Page 16: What's New In C# 5.0 - Programar 2013

DEMOAsync unit tests

Page 17: What's New In C# 5.0 - Programar 2013

Source Code Caller ID

Page 18: What's New In C# 5.0 - Programar 2013

Source Code Caller ID

CallerFilePathAttributeAllows you to obtain the full path of the source file that contains the caller. This is the file path at the time of compile.

http://msdn.microsoft.com/library/system.runtime.compilerservices.callerfilepathattribute.aspx

CallerLineNumberAttributeAllows you to obtain the line number in the source file at which the method is called.

http://msdn.microsoft.com/library/system.runtime.compilerservices.callerlinenumberattribute.aspx

CallerMemberNameAttributeAllows you to obtain the method or property name of the caller to the method.

http://msdn.microsoft.com/library/system.runtime.compilerservices.callermembernameattribute.aspx

# 18

Page 19: What's New In C# 5.0 - Programar 2013

Source Code Caller ID - Examples

# 19

static void TraceMessage( string message, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0){ Trace.WriteLine( string.Format( "{0} at {1} in {2}:line {3}", message, memberName, sourceFilePath, sourceLineNumber));}

Page 20: What's New In C# 5.0 - Programar 2013

Source Code Caller ID - Examples

# 20

private string field;public string Property{ get { return this.field; } set { if (this.field != value) { this.field = value; this.NotifyPropertyChanged(); } }}

protected void NotifyPropertyChanged([CallerMemberName] string propertyName = ""){ // …}

Page 21: What's New In C# 5.0 - Programar 2013

Breaking Changes

Page 22: What's New In C# 5.0 - Programar 2013

Breaking Changes

You can use the iteration variable of a foreach statement in a lambda expression that’s contained in the body of the loop.You can use the iteration variable of a foreach statement in a LINQ expression that’s contained in the body of the loop.Overload resolution has been improved for calls that use named arguments to access methods that contain params parameters.Overload resolution is improved for calls where the algorithm must choose between a Func<object> parameter and a Func parameter that has a different type parameter (e.g., string or int?) for a Func<dynamic> argument.Side effects from named and positional arguments in a method call now occur from left to right in the argument list.

http://msdn.microsoft.com/library/hh678682(v=vs.110).aspx

# 22

Page 23: What's New In C# 5.0 - Programar 2013

Resources

Page 24: What's New In C# 5.0 - Programar 2013

Resources

C# Referencehttp://msdn.microsoft.com/library/618ayhy6.aspx

Breaking Changes in C# 5.0http://msdn.microsoft.com/library/hh678682(v=vs.110).aspx

.NET Framework 4.5http://msdn.microsoft.com/library/vstudio/w0x726c2(v=vs.110).aspx

Task Parallel Library (TPL)http://msdn.microsoft.com/library/vstudio/dd460717.aspx

Asynchronous Programming with Async and Await (C# and Visual Basic)http://msdn.microsoft.com/library/hh191443.aspx

# 24

Page 25: What's New In C# 5.0 - Programar 2013

Resources

Task-based Asynchronous Patternhttp://msdn.microsoft.com/library/hh191443.aspx

Task.Run vs Task.Factory.StartNewhttp://blogs.msdn.com/b/pfxteam/archive/2011/10/24/10229468.aspx

An Async Premierhttp://msdn.microsoft.com/vstudio/jj573641.aspx

Eduasync by Jon Skeethttp://msmvps.com/blogs/jon_skeet/archive/tags/Eduasync/default.aspx

Eric Lippert's Bloghttp://ericlippert.com/http://blogs.msdn.com/b/ericlippert/archive/tags/c_2300_+5-0/async/

# 25

Page 26: What's New In C# 5.0 - Programar 2013

Resources

Lucian Wischik's Bloghttp://blogs.msdn.com/b/lucian/archive/tags/async/

Parallel Programming Team Bloghttp://blogs.msdn.com/b/pfxteam/archive/tags/async/

What’s new in C#5? – Red Gatehttp://www.youtube.com/watch?v=z7nry67oeKc

Novidades Do C# 5.0 – Comunidade NetPontohttp://www.youtube.com/watch?v=7Tl6CHf86z4

Sample Codehttp://code.msdn.microsoft.com/C-50-AsyncAwait-Demo-Code-334679a5

# 26

Page 27: What's New In C# 5.0 - Programar 2013

Resources

Paulo Morgado@PauloMorgadohttp://PauloMorgado.NET/http://mvp.support.microsoft.com/profile/Paulo.Morgadohttp://msmvps.com/blogs/paulomorgado/http://weblogs.asp.net/paulomorgado/http://pontonetpt.org/blogs/paulomorgado/http://www.codeproject.com/Members/PauloMorgadohttp://code.msdn.microsoft.com/site/search?f%5B0%5D.Type=User&f%5B0%5D.Value=Paulo%20Morgadohttp://www.codeplex.com/UserAccount/UserProfile.aspx?UserName=PauloMorgadohttp://www.slideshare.net/PauloJorgeMorgado

# 27

Page 28: What's New In C# 5.0 - Programar 2013

Q&A

Page 29: What's New In C# 5.0 - Programar 2013

Patrocinador Gold

Patrocinadores Silver

Page 30: What's New In C# 5.0 - Programar 2013

Media Partners

Page 31: What's New In C# 5.0 - Programar 2013

NOME DA APRESENTAÇÃO Nome (Nick no Fórum)

25 DE MAIO @MICROSOFT

Thank You!Paulo Morgado (paulo.morgado)