SlideShare a Scribd company logo
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

More Related Content

PDF
Chapter 2 - Structure of C++ Program
PPT
Unsafe
DOC
Week3 dq4
TXT
5 subtitles (text) for tutorial working on the programming assignments (8-47)
PDF
Concurrency and Parallelism with Scala
PPTX
Method and decorator
PDF
Tutorial basic of c ++lesson 1 eng ver
Chapter 2 - Structure of C++ Program
Unsafe
Week3 dq4
5 subtitles (text) for tutorial working on the programming assignments (8-47)
Concurrency and Parallelism with Scala
Method and decorator
Tutorial basic of c ++lesson 1 eng ver

What's hot (10)

PPTX
Login and private message
PDF
Access Tokens from Metamask
PDF
Logical Expressions in C/C++. Mistakes Made by Professionals
PPTX
Iterable, iterator, generator by gaurav khurana
PPTX
Conditional Rendering and rendering list in LWC
PDF
PPTX
Intro To C++ - Class 04 - An Introduction To C++ Programming, Part III
PPT
Module 4: Introduction to ASP.NET 3.5 (PowerPoint Slides)
Login and private message
Access Tokens from Metamask
Logical Expressions in C/C++. Mistakes Made by Professionals
Iterable, iterator, generator by gaurav khurana
Conditional Rendering and rendering list in LWC
Intro To C++ - Class 04 - An Introduction To C++ Programming, Part III
Module 4: Introduction to ASP.NET 3.5 (PowerPoint Slides)
Ad

Similar to C# 5.0 (20)

PPT
Asynchronous in dot net4
PPTX
Async pattern
PPT
C# Async on iOS and Android - Craig Dunn, Developer Evangelist at Xamarin
PPTX
Async Programming in C# 5
PPTX
Architectural Patterns - Interactive and Event Handling Patterns
PPTX
CSharp 5 Async
PPTX
Training – Going Async
PDF
Using Async in your Mobile Apps - Marek Safar
PPT
2310 b 14
PPTX
Async in .NET
PDF
Node.js: Continuation-Local-Storage and the Magic of AsyncListener
PPTX
Ddd melbourne 2011 C# async ctp
PPT
Introduction to synchronous programming langauges
PPT
Web Services 8
PPTX
Serverless meetup - OpenWhisk overview and architecture
PDF
Why async matters
PDF
Async Await for Mobile Apps
PPT
Module 1 Introduction
PPT
Call Back
PPT
Call Back
Asynchronous in dot net4
Async pattern
C# Async on iOS and Android - Craig Dunn, Developer Evangelist at Xamarin
Async Programming in C# 5
Architectural Patterns - Interactive and Event Handling Patterns
CSharp 5 Async
Training – Going Async
Using Async in your Mobile Apps - Marek Safar
2310 b 14
Async in .NET
Node.js: Continuation-Local-Storage and the Magic of AsyncListener
Ddd melbourne 2011 C# async ctp
Introduction to synchronous programming langauges
Web Services 8
Serverless meetup - OpenWhisk overview and architecture
Why async matters
Async Await for Mobile Apps
Module 1 Introduction
Call Back
Call Back
Ad

Recently uploaded (20)

PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Introduction-to-Social-Work-by-Leonora-Serafeca-De-Guzman-Group-2.pdf
PDF
Basic Mud Logging Guide for educational purpose
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
01-Introduction-to-Information-Management.pdf
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PPTX
Cell Structure & Organelles in detailed.
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Open folder Downloads.pdf yes yes ges yes
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Cardiovascular Pharmacology for pharmacy students.pptx
human mycosis Human fungal infections are called human mycosis..pptx
Introduction-to-Social-Work-by-Leonora-Serafeca-De-Guzman-Group-2.pdf
Basic Mud Logging Guide for educational purpose
O7-L3 Supply Chain Operations - ICLT Program
01-Introduction-to-Information-Management.pdf
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
Cell Structure & Organelles in detailed.
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Abdominal Access Techniques with Prof. Dr. R K Mishra
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPH.pptx obstetrics and gynecology in nursing
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Open folder Downloads.pdf yes yes ges yes
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Cardiovascular Pharmacology for pharmacy students.pptx

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

Editor's Notes

  • #4: 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
  • #5: Because Task has GetAwaiter Method
  • #7: 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
  • #9: - 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;)