SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances

Login and private message
Login and private messageLogin and private message
Login and private message
gueste832a8e
 

Tendances (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)
 

Similaire à C# 5.0

Asynchronous in dot net4
Asynchronous in dot net4Asynchronous in dot net4
Asynchronous in dot net4
Wei Sun
 
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
Xamarin
 
Async in .NET
Async in .NETAsync in .NET
Async in .NET
RTigger
 
Introduction to synchronous programming langauges
Introduction to synchronous programming langaugesIntroduction to synchronous programming langauges
Introduction to synchronous programming langauges
Akshar Desai
 
Web Services 8
Web Services 8Web Services 8
Web Services 8
pradeepfdo
 

Similaire à 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
 
Call Back
Call BackCall Back
Call Back
 
Call Back
Call BackCall Back
Call Back
 

Dernier

會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 

Dernier (20)

REPRODUCTIVE TOXICITY STUDIE OF MALE AND FEMALEpptx
REPRODUCTIVE TOXICITY  STUDIE OF MALE AND FEMALEpptxREPRODUCTIVE TOXICITY  STUDIE OF MALE AND FEMALEpptx
REPRODUCTIVE TOXICITY STUDIE OF MALE AND FEMALEpptx
 
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
 
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
 
Morse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptxMorse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptx
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
 
Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17
 
Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
Word Stress rules esl .pptx
Word Stress rules esl               .pptxWord Stress rules esl               .pptx
Word Stress rules esl .pptx
 
The Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. HenryThe Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. Henry
 
....................Muslim-Law notes.pdf
....................Muslim-Law notes.pdf....................Muslim-Law notes.pdf
....................Muslim-Law notes.pdf
 
How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17
 
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
 
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
 
How to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 InventoryHow to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 Inventory
 
MichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdfMichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdf
 

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

Notes de l'éditeur

  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;)