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
Asynchronous programming - .NET Way
PPTX
Asynchronous programming
PDF
Spring boot introduction
PDF
REST API and CRUD
PPTX
JavaScript Promises
PPTX
ASP.NET Web API
Async Programming in C# 5
Asynchronous programming in C#
Asynchronous programming - .NET Way
Asynchronous programming
Spring boot introduction
REST API and CRUD
JavaScript Promises
ASP.NET Web API

What's hot (20)

PDF
Java 8 features
PPTX
C# Async Await
PPTX
Introduction to java 8 stream api
PDF
Spring Framework - Core
PPTX
Spring boot
PPTX
PDF
Spring Framework - AOP
PDF
Spring boot jpa
PDF
TypeScript - An Introduction
PDF
Spring Boot
PPTX
ASP.NET Core MVC + Web API with Overview
PPT
Jsp/Servlet
PDF
ES6 presentation
PPTX
Jenkins tutorial
PPTX
Introduction to Node js
PDF
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
PPTX
SpringBoot with MyBatis, Flyway, QueryDSL
PPTX
Ajax ppt - 32 slides
PPTX
Springboot Microservices
PPT
Maven Introduction
Java 8 features
C# Async Await
Introduction to java 8 stream api
Spring Framework - Core
Spring boot
Spring Framework - AOP
Spring boot jpa
TypeScript - An Introduction
Spring Boot
ASP.NET Core MVC + Web API with Overview
Jsp/Servlet
ES6 presentation
Jenkins tutorial
Introduction to Node js
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
SpringBoot with MyBatis, Flyway, QueryDSL
Ajax ppt - 32 slides
Springboot Microservices
Maven Introduction
Ad

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

PPTX
History of asynchronous in .NET
PPTX
Training – Going Async
PPTX
CSharp 5 Async
PPTX
NDC Sydney 2019 - Async Demystified -- Karel Zikmund
PPTX
Async CTP 3 Presentation for MUGH 2012
PPTX
.NET Core Summer event 2019 in Brno, CZ - Async demystified -- Karel Zikmund
PPTX
End to-end async and await
PDF
Asynchronous programming in .net 4.5 with c#
PPTX
Binary Studio Academy: Concurrency in C# 5.0
PPTX
Async in .NET
PPTX
Async await
PDF
.Net Multithreading and Parallelization
PPTX
MobConf - session on C# async-await on 18june2016 at Kochi
PPTX
Async/Await
PDF
Async Await for Mobile Apps
PPTX
Welcome to an asynchronous world 1.29s
PPTX
Task parallel library presentation
PPTX
C# 5 deep drive into asynchronous programming
PPTX
Async programming in c#
PPTX
Asynchronous Programming in .NET
History of asynchronous in .NET
Training – Going Async
CSharp 5 Async
NDC Sydney 2019 - Async Demystified -- Karel Zikmund
Async CTP 3 Presentation for MUGH 2012
.NET Core Summer event 2019 in Brno, CZ - Async demystified -- Karel Zikmund
End to-end async and await
Asynchronous programming in .net 4.5 with c#
Binary Studio Academy: Concurrency in C# 5.0
Async in .NET
Async await
.Net Multithreading and Parallelization
MobConf - session on C# async-await on 18june2016 at Kochi
Async/Await
Async Await for Mobile Apps
Welcome to an asynchronous world 1.29s
Task parallel library presentation
C# 5 deep drive into asynchronous programming
Async programming in c#
Asynchronous Programming in .NET
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
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
history of c programming in notes for students .pptx
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
top salesforce developer skills in 2025.pdf
PDF
System and Network Administraation Chapter 3
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
Online Work Permit System for Fast Permit Processing
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
CHAPTER 2 - PM Management and IT Context
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
medical staffing services at VALiNTRY
PPTX
Odoo POS Development Services by CandidRoot Solutions
Design an Analysis of Algorithms I-SECS-1021-03
history of c programming in notes for students .pptx
Odoo Companies in India – Driving Business Transformation.pdf
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
Understanding Forklifts - TECH EHS Solution
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Design an Analysis of Algorithms II-SECS-1021-03
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
VVF-Customer-Presentation2025-Ver1.9.pptx
top salesforce developer skills in 2025.pdf
System and Network Administraation Chapter 3
Softaken Excel to vCard Converter Software.pdf
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Online Work Permit System for Fast Permit Processing
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
CHAPTER 2 - PM Management and IT Context
ManageIQ - Sprint 268 Review - Slide Deck
medical staffing services at VALiNTRY
Odoo POS Development Services by CandidRoot Solutions

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 :- vikashk@mindfiresolutions.com / viku85@gmail.com 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