SlideShare ist ein Scribd-Unternehmen logo
1 von 11
C # 5.0
New Features
By S. M. Ali Raza Naqvi
Senior Software Engineer
Agenda

Basic introduction to Async and Await keywords
Tracing attributes:
CallerFilePathAttribute, CallerLineNumberAttribute
and CallerMemberNameAttribute (if we got time)
Async & Await

A keyword use to create async methods
Async method must contains ‘Await’ keyword
Async methods invoke synchronously
Await is the point where method suspend and resume
asynchronously
Purpose of Await keyword is to wait for the task to
complete
Async & Await (Cont.)

Only methods that return void, Task or Task<Tresult>
can mark as Async
Methods which can’t mark async: Main, method
implementing synchronized attribute or security
Await can’t be use
in methods that are not mark Async
Inside Properties
Inside lock, catch or finally block
Async & Await - Flow

Output:
Async & Await - Behind the scene

Compiler uses state machine to track the current
state of the flow
State machine holds the parameters, local variables
and the current state of the method
When encounter await, It stores state machine object
as variable and resume it when awaiter gets the
response
Async & Await - Ease

Readable and maintainable code
Allow you to write asynchronous code in synchronous
fashion
Exception handling using try..catch block
Exceptions with much more details
Allow you to use “using” block
Async & Await - Moreover

You can create customize awaitable types using
IAwaitable interface
You can cancel an existing ongoing task using
CancellationTokenSource object
You can deal with multiple task all at once and can use
await for all of them at a time
Lets see the Code
Tracing attributes:
CallerFilePathAttribute, CallerLineNumberAttribute
and CallerMemberNameAttribute

You can obtain information about the caller to a
method
To help in tracing
CallerFilePath – return the caller’s file location
CallerLineNumber – return the line number from
where that method called
CallerMemberName – return the name of the method
that calls that method
Tracing attributes: CallerFilePathAttribute,
CallerLineNumberAttribute and
CallerMemberNameAttribute (Cont.)

It don’t involve any reflection

At compile time

Weitere ähnliche Inhalte

Was ist angesagt?

Login and private message
Login and private messageLogin and private message
Login and private messagegueste832a8e
 
Access Tokens from Metamask
Access Tokens from MetamaskAccess Tokens from Metamask
Access Tokens from MetamaskKC Tam
 
Logical Expressions in C/C++. Mistakes Made by Professionals
Logical Expressions in C/C++. Mistakes Made by ProfessionalsLogical Expressions in C/C++. Mistakes Made by Professionals
Logical Expressions in C/C++. Mistakes Made by ProfessionalsPVS-Studio
 
Iterable, iterator, generator by gaurav khurana
Iterable, iterator, generator by gaurav khuranaIterable, iterator, generator by gaurav khurana
Iterable, iterator, generator by gaurav khuranaGaurav Khurana
 
Conditional Rendering and rendering list in LWC
Conditional Rendering and rendering list in LWCConditional Rendering and rendering list in LWC
Conditional Rendering and rendering list in LWCSmritiSharan1
 
Intro To C++ - Class 04 - An Introduction To C++ Programming, Part III
Intro To C++ - Class 04 - An Introduction To C++ Programming, Part IIIIntro To C++ - Class 04 - An Introduction To C++ Programming, Part III
Intro To C++ - Class 04 - An Introduction To C++ Programming, Part IIIBlue Elephant Consulting
 
Module 4: Introduction to ASP.NET 3.5 (PowerPoint Slides)
Module 4: Introduction to ASP.NET 3.5 (PowerPoint Slides)Module 4: Introduction to ASP.NET 3.5 (PowerPoint Slides)
Module 4: Introduction to ASP.NET 3.5 (PowerPoint Slides)Mohamed Saleh
 

Was ist angesagt? (10)

Login and private message
Login and private messageLogin and private message
Login and private message
 
ACM init()- Day 4
ACM init()- Day 4ACM init()- Day 4
ACM init()- Day 4
 
Access Tokens from Metamask
Access Tokens from MetamaskAccess Tokens from Metamask
Access Tokens from Metamask
 
Start with swift
Start with swiftStart with swift
Start with swift
 
Logical Expressions in C/C++. Mistakes Made by Professionals
Logical Expressions in C/C++. Mistakes Made by ProfessionalsLogical Expressions in C/C++. Mistakes Made by Professionals
Logical Expressions in C/C++. Mistakes Made by Professionals
 
Iterable, iterator, generator by gaurav khurana
Iterable, iterator, generator by gaurav khuranaIterable, iterator, generator by gaurav khurana
Iterable, iterator, generator by gaurav khurana
 
Conditional Rendering and rendering list in LWC
Conditional Rendering and rendering list in LWCConditional Rendering and rendering list in LWC
Conditional Rendering and rendering list in LWC
 
Output
OutputOutput
Output
 
Intro To C++ - Class 04 - An Introduction To C++ Programming, Part III
Intro To C++ - Class 04 - An Introduction To C++ Programming, Part IIIIntro To C++ - Class 04 - An Introduction To C++ Programming, Part III
Intro To C++ - Class 04 - An Introduction To C++ Programming, Part III
 
Module 4: Introduction to ASP.NET 3.5 (PowerPoint Slides)
Module 4: Introduction to ASP.NET 3.5 (PowerPoint Slides)Module 4: Introduction to ASP.NET 3.5 (PowerPoint Slides)
Module 4: Introduction to ASP.NET 3.5 (PowerPoint Slides)
 

Ähnlich wie C# 5.0

Asynchronous in dot net4
Asynchronous in dot net4Asynchronous in dot net4
Asynchronous in dot net4Wei Sun
 
C# Async on iOS and Android - Craig Dunn, Developer Evangelist at Xamarin
C# Async on iOS and Android - Craig Dunn, Developer Evangelist at XamarinC# Async on iOS and Android - Craig Dunn, Developer Evangelist at Xamarin
C# Async on iOS and Android - Craig Dunn, Developer Evangelist at XamarinXamarin
 
Architectural Patterns - Interactive and Event Handling Patterns
Architectural Patterns  - Interactive and Event Handling PatternsArchitectural Patterns  - Interactive and Event Handling Patterns
Architectural Patterns - Interactive and Event Handling Patternsassinha
 
Using Async in your Mobile Apps - Marek Safar
Using Async in your Mobile Apps - Marek SafarUsing Async in your Mobile Apps - Marek Safar
Using Async in your Mobile Apps - Marek SafarXamarin
 
Async in .NET
Async in .NETAsync in .NET
Async in .NETRTigger
 
Node.js: Continuation-Local-Storage and the Magic of AsyncListener
Node.js: Continuation-Local-Storage and the Magic of AsyncListenerNode.js: Continuation-Local-Storage and the Magic of AsyncListener
Node.js: Continuation-Local-Storage and the Magic of AsyncListenerIslam Sharabash
 
Ddd melbourne 2011 C# async ctp
Ddd melbourne 2011  C# async ctpDdd melbourne 2011  C# async ctp
Ddd melbourne 2011 C# async ctpPratik Khasnabis
 
Introduction to synchronous programming langauges
Introduction to synchronous programming langaugesIntroduction to synchronous programming langauges
Introduction to synchronous programming langaugesAkshar Desai
 
Web Services 8
Web Services 8Web Services 8
Web Services 8pradeepfdo
 
Serverless meetup - OpenWhisk overview and architecture
Serverless meetup - OpenWhisk overview and architectureServerless meetup - OpenWhisk overview and architecture
Serverless meetup - OpenWhisk overview and architectureSandeep Paliwal
 
Why async matters
Why async mattersWhy async matters
Why async matterstimbc
 
Async Await for Mobile Apps
Async Await for Mobile AppsAsync Await for Mobile Apps
Async Await for Mobile AppsCraig Dunn
 
Module 1 Introduction
Module 1   IntroductionModule 1   Introduction
Module 1 Introductionleminhvuong
 

Ähnlich wie C# 5.0 (20)

Asynchronous in dot net4
Asynchronous in dot net4Asynchronous in dot net4
Asynchronous in dot net4
 
Async pattern
Async patternAsync pattern
Async pattern
 
C# Async on iOS and Android - Craig Dunn, Developer Evangelist at Xamarin
C# Async on iOS and Android - Craig Dunn, Developer Evangelist at XamarinC# Async on iOS and Android - Craig Dunn, Developer Evangelist at Xamarin
C# Async on iOS and Android - Craig Dunn, Developer Evangelist at Xamarin
 
Async Programming in C# 5
Async Programming in C# 5Async Programming in C# 5
Async Programming in C# 5
 
Architectural Patterns - Interactive and Event Handling Patterns
Architectural Patterns  - Interactive and Event Handling PatternsArchitectural Patterns  - Interactive and Event Handling Patterns
Architectural Patterns - Interactive and Event Handling Patterns
 
CSharp 5 Async
CSharp 5 AsyncCSharp 5 Async
CSharp 5 Async
 
Training – Going Async
Training – Going AsyncTraining – Going Async
Training – Going Async
 
Using Async in your Mobile Apps - Marek Safar
Using Async in your Mobile Apps - Marek SafarUsing Async in your Mobile Apps - Marek Safar
Using Async in your Mobile Apps - Marek Safar
 
2310 b 14
2310 b 142310 b 14
2310 b 14
 
Async in .NET
Async in .NETAsync in .NET
Async in .NET
 
Node.js: Continuation-Local-Storage and the Magic of AsyncListener
Node.js: Continuation-Local-Storage and the Magic of AsyncListenerNode.js: Continuation-Local-Storage and the Magic of AsyncListener
Node.js: Continuation-Local-Storage and the Magic of AsyncListener
 
Ddd melbourne 2011 C# async ctp
Ddd melbourne 2011  C# async ctpDdd melbourne 2011  C# async ctp
Ddd melbourne 2011 C# async ctp
 
Introduction to synchronous programming langauges
Introduction to synchronous programming langaugesIntroduction to synchronous programming langauges
Introduction to synchronous programming langauges
 
Web Services 8
Web Services 8Web Services 8
Web Services 8
 
Serverless meetup - OpenWhisk overview and architecture
Serverless meetup - OpenWhisk overview and architectureServerless meetup - OpenWhisk overview and architecture
Serverless meetup - OpenWhisk overview and architecture
 
Why async matters
Why async mattersWhy async matters
Why async matters
 
Async Await for Mobile Apps
Async Await for Mobile AppsAsync Await for Mobile Apps
Async Await for Mobile Apps
 
Call Back
Call BackCall Back
Call Back
 
Module 1 Introduction
Module 1   IntroductionModule 1   Introduction
Module 1 Introduction
 
Call Back
Call BackCall Back
Call Back
 

Kürzlich hochgeladen

Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 

Kürzlich hochgeladen (20)

Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 

C# 5.0

  • 1. C # 5.0 New Features By S. M. Ali Raza Naqvi Senior Software Engineer
  • 2. Agenda Basic introduction to Async and Await keywords Tracing attributes: CallerFilePathAttribute, CallerLineNumberAttribute and CallerMemberNameAttribute (if we got time)
  • 3. Async & Await A keyword use to create async methods Async method must contains ‘Await’ keyword Async methods invoke synchronously Await is the point where method suspend and resume asynchronously Purpose of Await keyword is to wait for the task to complete
  • 4. Async & Await (Cont.) Only methods that return void, Task or Task<Tresult> can mark as Async Methods which can’t mark async: Main, method implementing synchronized attribute or security Await can’t be use in methods that are not mark Async Inside Properties Inside lock, catch or finally block
  • 5. Async & Await - Flow Output:
  • 6. Async & Await - Behind the scene Compiler uses state machine to track the current state of the flow State machine holds the parameters, local variables and the current state of the method When encounter await, It stores state machine object as variable and resume it when awaiter gets the response
  • 7. Async & Await - Ease Readable and maintainable code Allow you to write asynchronous code in synchronous fashion Exception handling using try..catch block Exceptions with much more details Allow you to use “using” block
  • 8. Async & Await - Moreover You can create customize awaitable types using IAwaitable interface You can cancel an existing ongoing task using CancellationTokenSource object You can deal with multiple task all at once and can use await for all of them at a time
  • 10. Tracing attributes: CallerFilePathAttribute, CallerLineNumberAttribute and CallerMemberNameAttribute You can obtain information about the caller to a method To help in tracing CallerFilePath – return the caller’s file location CallerLineNumber – return the line number from where that method called CallerMemberName – return the name of the method that calls that method
  • 11. Tracing attributes: CallerFilePathAttribute, CallerLineNumberAttribute and CallerMemberNameAttribute (Cont.) It don’t involve any reflection At compile time

Hinweis der Redaktion

  1. if you have a synchronous method that returns void and all you do to change it is mark it as “async”, invocations of that method will still run synchronouslySimilarly, if you have a synchronous method that returns some TResult, and all you do is mark it as “async” and change the return type to be “Task&lt;TResult&gt;”, invocations of that method will still run synchronously.if “await” isn’t used at all in a method’s code, there will only be one piece, and since that piece will start running synchronouslyIAwaiter an interface that contains callback methods
  2. Because Task has GetAwaiter Method
  3. For example: If you have a single Await keyword in your aysnc method. Then the compiler will create the state machine with 2 methods. One will contains the code from the first line of the method till Await line and the other method will contain the rest of the logic. Then the compiler executes the first method first and then move to main method from where it calls that async method and then when the awaited task (which was fired in the first method) returns the response then it calls the second method
  4. - http://weblogs.asp.net/dixin/archive/2012/11/08/understanding-c-async-await-2-awaitable-awaiter-pattern.aspxhttp://enumeratethis.com/2010/11/03/c-5-0-rx-schedulers/InitializeCancellationTokeSouce global object under async method and then call its Cancel method when you want to cancel the on going taskAwait Task.Whenall(&lt;list of tasks&gt;)