SlideShare a Scribd company logo
Asynchronous Programming in C#
- Part 1
Presenter: Vikash Kumar, Mindfire Solutions
(28/07/2014)
About Me
MCTS-70-515 - Microsoft .NET 4.0, Web App
Development
MCP:70-483: MS - Programming in C#
Skills: MVC, Asp.Net WebForms, C#,
EntityFramework, OpenAccess, TypeScript,
SEO, jQuery, KendoUI, Lucene.Net,
Asynchronous programming, Sql Server.
Connect Me:
Blog :- http://vikutech.blogspot.in/
Twitter :- https://twitter.com/viku85
LinkedIn :- http://www.linkedin.com/pub/vikash-kumar/11/4b5/625
Google+ :- https://plus.google.com/108754146104237310375
Contact Me:
Email :- vikashk@mindfiresolutions.com / viku85@gmail.com
Skype :- mfsi_vikash
Agenda

What is asynchronous?

Asynchronous programming options and history

Thread and ThreadPool

Asynchronous Programming Model (APM)

Event-based Asynchronous Pattern (EAP)

Task
– Basics
– Exception handling
– Relationships
What is asynchronous?
Image Source: http://www.webopedia.com/
To do more than one thing at a time.
asyn = not with
chronos = time
Asynchronous programming
options and history

Thread

Asynchronous Programming Model (APM)

Event-Based Asynchronous Pattern (EAP)

BackgroundWorker

Task

Task Parallel Library - DataFlow

Task Parallel Library – Parallel APIs

Thread → APM → EAP → TAP
Thread and ThreadPool

Basic building block for async programming.

Parameterize thread, came with .NET 2.0
Image source:http://johnpaulmorabito.blogspot.in/
APM and EAP

APM depends upon Begin and End methods.

Callbacks are dependent on IAsyncResult.

EAP came with .NET 2.0 which automatically
handles synchronization context.

BackgroundWorker is an example of EAP based
programming.

EAP can be seen while adding web reference
which automatically creates with proxies classes.
APM and EAP
Task

A task is an abstraction of unit of work to run
asynchronously.

Ways to execute: new Task(Speak).Start(),
Task.Factory.StartNew(Speak),
Task.Run(Speak)

Use FromAsync when an API has
BeginXXX/EndXXX.

Task can be canceled through
CancellationToken and checked with
ThrowIfCancellationRequested.

IProgress<T> came with 4.5 which can be
used to show status
Task error handling

Task are completed with following state: Ran to
Completion, Canceled and Faulted.

Task uses AggregateException to wrap up any
other exception occurs which can be found under
inner exception.

AggregateException comes with Flatten method to
check all exceptions.

AggregateException also comes with Handle
method which accepts predicate to handle errors.

ThrowUnobservedTaskExceptions to configure
to shallow exception.
Cancellation
FromAsync
Progress bar
Exception handling
Task Relationships
Task
Task Task Task
Child Tasks
Task Task Task
Chained Task
Task Relationships...

ContinueWhenXXX can be used to chain up
tasks with TaskContinuationOptions enum for
various conditions.

TaskCreationOptions.AttachedToParent is
used to create child tasks.

Creating child task will reflect exception in parent
task if exception occurs.

Task.Run uses
TaskCreationOptions.DenyChildAttach by
default which will act as nested task.
Task Relationship
Presenter: XXXX XXXX, Mindfire Solutions
Question and
Answer
References

Pro Asynchronous Programming with .NET
 Asynchronous Programming Patterns
 Asynchronous Programming in .NET: I'll Call You Bac
(For definition)
Presenter: Vikash Kumar, Mindfire Solutions
Thank you
www.mindfiresolutions.com
https://www.facebook.com/MindfireSolutions
http://www.linkedin.com/company/mindfire-solutions
http://twitter.com/mindfires

More Related Content

PPTX
Asynchronous programming in C#
Bohdan Pashkovskyi
 
PPTX
C# Async Await
Simplilearn
 
PPTX
Asynchronous programming - .NET Way
Bishnu Rawal
 
PPTX
Node.js Express
Eyal Vardi
 
PDF
Intro to Asynchronous Javascript
Garrett Welson
 
PDF
Express node js
Yashprit Singh
 
PDF
Angular
Lilia Sfaxi
 
PPTX
Asynchronous Programming in .NET
Pierre-Luc Maheu
 
Asynchronous programming in C#
Bohdan Pashkovskyi
 
C# Async Await
Simplilearn
 
Asynchronous programming - .NET Way
Bishnu Rawal
 
Node.js Express
Eyal Vardi
 
Intro to Asynchronous Javascript
Garrett Welson
 
Express node js
Yashprit Singh
 
Angular
Lilia Sfaxi
 
Asynchronous Programming in .NET
Pierre-Luc Maheu
 

What's hot (20)

PDF
Angular 2 observables
Geoffrey Filippi
 
PPTX
Modern JS with ES6
Kevin Langley Jr.
 
PDF
The Secret Life of a Bug Bounty Hunter – Frans Rosén @ Security Fest 2016
Frans Rosén
 
PPTX
Build RESTful API Using Express JS
Cakra Danu Sedayu
 
PDF
Asynchronous JavaScript Programming
Haim Michael
 
PDF
Introduction to ReactJS
Hoang Long
 
ODP
Routing & Navigating Pages in Angular 2
Knoldus Inc.
 
PPTX
Introduction to angular with a simple but complete project
Jadson Santos
 
PPT
Angular 8
Sunil OS
 
PDF
Redux Toolkit - Quick Intro - 2022
Fabio Biondi
 
ODP
Introduction to Swagger
Knoldus Inc.
 
PDF
Asynchronous JavaScript Programming with Callbacks & Promises
Hùng Nguyễn Huy
 
PDF
Angular - Chapter 5 - Directives
WebStackAcademy
 
PDF
Spring Framework - AOP
Dzmitry Naskou
 
PDF
Angular - Chapter 7 - HTTP Services
WebStackAcademy
 
PDF
Understanding MicroSERVICE Architecture with Java & Spring Boot
Kashif Ali Siddiqui
 
PPTX
JS Event Loop
Saai Vignesh P
 
PPTX
Sharing Data Between Angular Components
Squash Apps Pvt Ltd
 
PPTX
Asynchronous programming
Filip Ekberg
 
PPTX
React hooks
Sadhna Rana
 
Angular 2 observables
Geoffrey Filippi
 
Modern JS with ES6
Kevin Langley Jr.
 
The Secret Life of a Bug Bounty Hunter – Frans Rosén @ Security Fest 2016
Frans Rosén
 
Build RESTful API Using Express JS
Cakra Danu Sedayu
 
Asynchronous JavaScript Programming
Haim Michael
 
Introduction to ReactJS
Hoang Long
 
Routing & Navigating Pages in Angular 2
Knoldus Inc.
 
Introduction to angular with a simple but complete project
Jadson Santos
 
Angular 8
Sunil OS
 
Redux Toolkit - Quick Intro - 2022
Fabio Biondi
 
Introduction to Swagger
Knoldus Inc.
 
Asynchronous JavaScript Programming with Callbacks & Promises
Hùng Nguyễn Huy
 
Angular - Chapter 5 - Directives
WebStackAcademy
 
Spring Framework - AOP
Dzmitry Naskou
 
Angular - Chapter 7 - HTTP Services
WebStackAcademy
 
Understanding MicroSERVICE Architecture with Java & Spring Boot
Kashif Ali Siddiqui
 
JS Event Loop
Saai Vignesh P
 
Sharing Data Between Angular Components
Squash Apps Pvt Ltd
 
Asynchronous programming
Filip Ekberg
 
React hooks
Sadhna Rana
 
Ad

Similar to Asynchronous Programming in C# - Part 1 (20)

PPTX
History of asynchronous in .NET
Marcin Tyborowski
 
PPTX
Training – Going Async
Betclic Everest Group Tech Team
 
PPTX
CSharp 5 Async
Valdis Iljuconoks
 
PPTX
NDC Sydney 2019 - Async Demystified -- Karel Zikmund
Karel Zikmund
 
PPTX
Async CTP 3 Presentation for MUGH 2012
Sri Kanth
 
PPTX
.NET Core Summer event 2019 in Brno, CZ - Async demystified -- Karel Zikmund
Karel Zikmund
 
PPTX
End to-end async and await
vfabro
 
PDF
Asynchronous programming in .net 4.5 with c#
Binu Bhasuran
 
PPTX
Binary Studio Academy: Concurrency in C# 5.0
Binary Studio
 
PPTX
Async in .NET
RTigger
 
PPTX
Async await
Jeff Hart
 
PDF
.Net Multithreading and Parallelization
Dmitri Nesteruk
 
PPTX
MobConf - session on C# async-await on 18june2016 at Kochi
Praveen Nair
 
PPTX
Async/Await
Jeff Hart
 
PDF
Async Await for Mobile Apps
Craig Dunn
 
PPTX
Welcome to an asynchronous world 1.29s
Jose Luis Latorre Millas
 
PPTX
Task parallel library presentation
ahmed sayed
 
PPTX
C# 5 deep drive into asynchronous programming
Praveen Prajapati
 
PPTX
Async programming in c#
Ahasanul Kalam Akib
 
PDF
Webcast: Asynchronous Programming Demystified
Serge Baranovsky
 
History of asynchronous in .NET
Marcin Tyborowski
 
Training – Going Async
Betclic Everest Group Tech Team
 
CSharp 5 Async
Valdis Iljuconoks
 
NDC Sydney 2019 - Async Demystified -- Karel Zikmund
Karel Zikmund
 
Async CTP 3 Presentation for MUGH 2012
Sri Kanth
 
.NET Core Summer event 2019 in Brno, CZ - Async demystified -- Karel Zikmund
Karel Zikmund
 
End to-end async and await
vfabro
 
Asynchronous programming in .net 4.5 with c#
Binu Bhasuran
 
Binary Studio Academy: Concurrency in C# 5.0
Binary Studio
 
Async in .NET
RTigger
 
Async await
Jeff Hart
 
.Net Multithreading and Parallelization
Dmitri Nesteruk
 
MobConf - session on C# async-await on 18june2016 at Kochi
Praveen Nair
 
Async/Await
Jeff Hart
 
Async Await for Mobile Apps
Craig Dunn
 
Welcome to an asynchronous world 1.29s
Jose Luis Latorre Millas
 
Task parallel library presentation
ahmed sayed
 
C# 5 deep drive into asynchronous programming
Praveen Prajapati
 
Async programming in c#
Ahasanul Kalam Akib
 
Webcast: Asynchronous Programming Demystified
Serge Baranovsky
 
Ad

More from Mindfire Solutions (20)

PDF
Physician Search and Review
Mindfire Solutions
 
PDF
diet management app
Mindfire Solutions
 
PDF
Business Technology Solution
Mindfire Solutions
 
PDF
Remote Health Monitoring
Mindfire Solutions
 
PDF
Influencer Marketing Solution
Mindfire Solutions
 
PPT
High Availability of Azure Applications
Mindfire Solutions
 
PPTX
IOT Hands On
Mindfire Solutions
 
PPTX
Glimpse of Loops Vs Set
Mindfire Solutions
 
ODP
Oracle Sql Developer-Getting Started
Mindfire Solutions
 
PPT
Adaptive Layout In iOS 8
Mindfire Solutions
 
PPT
Introduction to Auto-layout : iOS/Mac
Mindfire Solutions
 
PPT
LINQPad - utility Tool
Mindfire Solutions
 
PPT
Get started with watch kit development
Mindfire Solutions
 
PPTX
Swift vs Objective-C
Mindfire Solutions
 
ODP
Material Design in Android
Mindfire Solutions
 
ODP
Introduction to OData
Mindfire Solutions
 
PPT
Ext js Part 2- MVC
Mindfire Solutions
 
PPT
ExtJs Basic Part-1
Mindfire Solutions
 
PPT
Spring Security Introduction
Mindfire Solutions
 
Physician Search and Review
Mindfire Solutions
 
diet management app
Mindfire Solutions
 
Business Technology Solution
Mindfire Solutions
 
Remote Health Monitoring
Mindfire Solutions
 
Influencer Marketing Solution
Mindfire Solutions
 
High Availability of Azure Applications
Mindfire Solutions
 
IOT Hands On
Mindfire Solutions
 
Glimpse of Loops Vs Set
Mindfire Solutions
 
Oracle Sql Developer-Getting Started
Mindfire Solutions
 
Adaptive Layout In iOS 8
Mindfire Solutions
 
Introduction to Auto-layout : iOS/Mac
Mindfire Solutions
 
LINQPad - utility Tool
Mindfire Solutions
 
Get started with watch kit development
Mindfire Solutions
 
Swift vs Objective-C
Mindfire Solutions
 
Material Design in Android
Mindfire Solutions
 
Introduction to OData
Mindfire Solutions
 
Ext js Part 2- MVC
Mindfire Solutions
 
ExtJs Basic Part-1
Mindfire Solutions
 
Spring Security Introduction
Mindfire Solutions
 

Recently uploaded (20)

PPTX
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
PDF
Become an Agentblazer Champion Challenge
Dele Amefo
 
PDF
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
PDF
49785682629390197565_LRN3014_Migrating_the_Beast.pdf
Abilash868456
 
PDF
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
ESUG
 
PPTX
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
PDF
Micromaid: A simple Mermaid-like chart generator for Pharo
ESUG
 
PDF
Why Use Open Source Reporting Tools for Business Intelligence.pdf
Varsha Nayak
 
PPTX
Presentation about variables and constant.pptx
safalsingh810
 
PPTX
GALILEO CRS SYSTEM | GALILEO TRAVEL SOFTWARE
philipnathen82
 
PPTX
Smart Panchayat Raj e-Governance App.pptx
Rohitnikam33
 
PDF
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
PDF
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
PDF
lesson-2-rules-of-netiquette.pdf.bshhsjdj
jasmenrojas249
 
PDF
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
PDF
Teaching Reproducibility and Embracing Variability: From Floating-Point Exper...
University of Rennes, INSA Rennes, Inria/IRISA, CNRS
 
PPTX
Explanation about Structures in C language.pptx
Veeral Rathod
 
PPT
Activate_Methodology_Summary presentatio
annapureddyn
 
PDF
IEEE-CS Tech Predictions, SWEBOK and Quantum Software: Towards Q-SWEBOK
Hironori Washizaki
 
PPTX
Why Use Open Source Reporting Tools for Business Intelligence.pptx
Varsha Nayak
 
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
Become an Agentblazer Champion Challenge
Dele Amefo
 
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
49785682629390197565_LRN3014_Migrating_the_Beast.pdf
Abilash868456
 
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
ESUG
 
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
Micromaid: A simple Mermaid-like chart generator for Pharo
ESUG
 
Why Use Open Source Reporting Tools for Business Intelligence.pdf
Varsha Nayak
 
Presentation about variables and constant.pptx
safalsingh810
 
GALILEO CRS SYSTEM | GALILEO TRAVEL SOFTWARE
philipnathen82
 
Smart Panchayat Raj e-Governance App.pptx
Rohitnikam33
 
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
lesson-2-rules-of-netiquette.pdf.bshhsjdj
jasmenrojas249
 
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
Teaching Reproducibility and Embracing Variability: From Floating-Point Exper...
University of Rennes, INSA Rennes, Inria/IRISA, CNRS
 
Explanation about Structures in C language.pptx
Veeral Rathod
 
Activate_Methodology_Summary presentatio
annapureddyn
 
IEEE-CS Tech Predictions, SWEBOK and Quantum Software: Towards Q-SWEBOK
Hironori Washizaki
 
Why Use Open Source Reporting Tools for Business Intelligence.pptx
Varsha Nayak
 

Asynchronous Programming in C# - Part 1

  • 1. Asynchronous Programming in C# - Part 1 Presenter: Vikash Kumar, Mindfire Solutions (28/07/2014)
  • 2. About Me MCTS-70-515 - Microsoft .NET 4.0, Web App Development MCP:70-483: MS - Programming in C# Skills: MVC, Asp.Net WebForms, C#, EntityFramework, OpenAccess, TypeScript, SEO, jQuery, KendoUI, Lucene.Net, Asynchronous programming, Sql Server. Connect Me: Blog :- http://vikutech.blogspot.in/ Twitter :- https://twitter.com/viku85 LinkedIn :- http://www.linkedin.com/pub/vikash-kumar/11/4b5/625 Google+ :- https://plus.google.com/108754146104237310375 Contact Me: Email :- [email protected] / [email protected] Skype :- mfsi_vikash
  • 3. Agenda  What is asynchronous?  Asynchronous programming options and history  Thread and ThreadPool  Asynchronous Programming Model (APM)  Event-based Asynchronous Pattern (EAP)  Task – Basics – Exception handling – Relationships
  • 4. What is asynchronous? Image Source: http://www.webopedia.com/ To do more than one thing at a time. asyn = not with chronos = time
  • 5. Asynchronous programming options and history  Thread  Asynchronous Programming Model (APM)  Event-Based Asynchronous Pattern (EAP)  BackgroundWorker  Task  Task Parallel Library - DataFlow  Task Parallel Library – Parallel APIs  Thread → APM → EAP → TAP
  • 6. Thread and ThreadPool  Basic building block for async programming.  Parameterize thread, came with .NET 2.0 Image source:http://johnpaulmorabito.blogspot.in/
  • 7. APM and EAP  APM depends upon Begin and End methods.  Callbacks are dependent on IAsyncResult.  EAP came with .NET 2.0 which automatically handles synchronization context.  BackgroundWorker is an example of EAP based programming.  EAP can be seen while adding web reference which automatically creates with proxies classes.
  • 9. Task  A task is an abstraction of unit of work to run asynchronously.  Ways to execute: new Task(Speak).Start(), Task.Factory.StartNew(Speak), Task.Run(Speak)  Use FromAsync when an API has BeginXXX/EndXXX.  Task can be canceled through CancellationToken and checked with ThrowIfCancellationRequested.  IProgress<T> came with 4.5 which can be used to show status
  • 10. Task error handling  Task are completed with following state: Ran to Completion, Canceled and Faulted.  Task uses AggregateException to wrap up any other exception occurs which can be found under inner exception.  AggregateException comes with Flatten method to check all exceptions.  AggregateException also comes with Handle method which accepts predicate to handle errors.  ThrowUnobservedTaskExceptions to configure to shallow exception.
  • 13. Task Relationships Task Task Task Task Child Tasks Task Task Task Chained Task
  • 14. Task Relationships...  ContinueWhenXXX can be used to chain up tasks with TaskContinuationOptions enum for various conditions.  TaskCreationOptions.AttachedToParent is used to create child tasks.  Creating child task will reflect exception in parent task if exception occurs.  Task.Run uses TaskCreationOptions.DenyChildAttach by default which will act as nested task.
  • 16. Presenter: XXXX XXXX, Mindfire Solutions Question and Answer
  • 17. References  Pro Asynchronous Programming with .NET  Asynchronous Programming Patterns  Asynchronous Programming in .NET: I'll Call You Bac (For definition)
  • 18. Presenter: Vikash Kumar, Mindfire Solutions Thank you