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
Async Programming in C# 5
PPTX
Asynchronous programming in C#
PPTX
C# Async Await
PPTX
Asynchronous programming - .NET Way
PPSX
Async-await best practices in 10 minutes
PPTX
Avoiding callback hell in Node js using promises
PDF
Ansible
PPTX
Introduction to node.js
Async Programming in C# 5
Asynchronous programming in C#
C# Async Await
Asynchronous programming - .NET Way
Async-await best practices in 10 minutes
Avoiding callback hell in Node js using promises
Ansible
Introduction to node.js

What's hot (20)

PPTX
Express js
PPTX
Asynchronous Programming in .NET
PDF
Ansible - Introduction
PPTX
Introduction to ansible
ODP
ansible why ?
PDF
Express node js
PPTX
Introduction to NodeJS
PPTX
Spring Boot and REST API
PDF
Low Level View of Android System Architecture
PDF
Rust system programming language
PPTX
Node.js Express
PPTX
Introduction to Ansible
PPTX
NGINX: High Performance Load Balancing
PPT
Spring ppt
PDF
Quarkus - a next-generation Kubernetes Native Java framework
PDF
VueJS Introduction
PPTX
Introduction to Node js
PPTX
JS Event Loop
PDF
Automate Oracle database patches and upgrades using Fleet Provisioning and Pa...
Express js
Asynchronous Programming in .NET
Ansible - Introduction
Introduction to ansible
ansible why ?
Express node js
Introduction to NodeJS
Spring Boot and REST API
Low Level View of Android System Architecture
Rust system programming language
Node.js Express
Introduction to Ansible
NGINX: High Performance Load Balancing
Spring ppt
Quarkus - a next-generation Kubernetes Native Java framework
VueJS Introduction
Introduction to Node js
JS Event Loop
Automate Oracle database patches and upgrades using Fleet Provisioning and Pa...
Ad

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

PPTX
Background thread
PPT
Qtp 9.2 examples
PDF
Release with confidence
DOCX
What is selenium
PPTX
Training – Going Async
PPTX
C# 5 deep drive into asynchronous programming
PPT
Introduction of exception in vb.net
PPTX
Ddd melbourne 2011 C# async ctp
PPTX
AsynchronousProgrammingDesignPatterns.pptx
PDF
Tdd is not about testing
PPTX
Salesforce Apex Hours:-Mitigate with Mono-Purpose Microservices
PDF
No Hugging, No Learning
PDF
JAVASCRIPT Test Driven Development & Jasmine
PPT
Working Effectively With Legacy Code
PPTX
DevOps: The New Face Of Application Development - Global Azure Bootcamp
PDF
Behavior & Specification Driven Development in PHP - #OpenWest
PPT
Why test with flex unit
PDF
London SF Developers: Custom Lightning Component Error Handling
PDF
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
DOCX
Introduction To Programming IP5
Background thread
Qtp 9.2 examples
Release with confidence
What is selenium
Training – Going Async
C# 5 deep drive into asynchronous programming
Introduction of exception in vb.net
Ddd melbourne 2011 C# async ctp
AsynchronousProgrammingDesignPatterns.pptx
Tdd is not about testing
Salesforce Apex Hours:-Mitigate with Mono-Purpose Microservices
No Hugging, No Learning
JAVASCRIPT Test Driven Development & Jasmine
Working Effectively With Legacy Code
DevOps: The New Face Of Application Development - Global Azure Bootcamp
Behavior & Specification Driven Development in PHP - #OpenWest
Why test with flex unit
London SF Developers: Custom Lightning Component Error Handling
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Introduction To Programming IP5
Ad

More from Mindfire Solutions (20)

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

Recently uploaded (20)

PDF
top salesforce developer skills in 2025.pdf
PDF
QAware_Mario-Leander_Reimer_Architecting and Building a K8s-based AI Platform...
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
System and Network Administraation Chapter 3
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
ISO 45001 Occupational Health and Safety Management System
PPTX
Materi_Pemrograman_Komputer-Looping.pptx
PDF
How to Confidently Manage Project Budgets
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Become an Agentblazer Champion Challenge Kickoff
PPTX
Introduction to Artificial Intelligence
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
AIRLINE PRICE API | FLIGHT API COST |
PPTX
L1 - Introduction to python Backend.pptx
PPTX
Materi-Enum-and-Record-Data-Type (1).pptx
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
medical staffing services at VALiNTRY
PDF
A REACT POMODORO TIMER WEB APPLICATION.pdf
top salesforce developer skills in 2025.pdf
QAware_Mario-Leander_Reimer_Architecting and Building a K8s-based AI Platform...
Odoo POS Development Services by CandidRoot Solutions
System and Network Administraation Chapter 3
How to Migrate SBCGlobal Email to Yahoo Easily
ISO 45001 Occupational Health and Safety Management System
Materi_Pemrograman_Komputer-Looping.pptx
How to Confidently Manage Project Budgets
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Become an Agentblazer Champion Challenge Kickoff
Introduction to Artificial Intelligence
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
AIRLINE PRICE API | FLIGHT API COST |
L1 - Introduction to python Backend.pptx
Materi-Enum-and-Record-Data-Type (1).pptx
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
medical staffing services at VALiNTRY
A REACT POMODORO TIMER WEB APPLICATION.pdf

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