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

What's hot

What's hot (20)

java 8 new features
java 8 new features java 8 new features
java 8 new features
 
Java web services
Java web servicesJava web services
Java web services
 
Functional Programming
Functional ProgrammingFunctional Programming
Functional Programming
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
Angular kickstart slideshare
Angular kickstart   slideshareAngular kickstart   slideshare
Angular kickstart slideshare
 
Angular modules in depth
Angular modules in depthAngular modules in depth
Angular modules in depth
 
ES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern JavascriptES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern Javascript
 
The New JavaScript: ES6
The New JavaScript: ES6The New JavaScript: ES6
The New JavaScript: ES6
 
React hooks
React hooksReact hooks
React hooks
 
Web Worker, Service Worker and Worklets
Web Worker, Service Worker and WorkletsWeb Worker, Service Worker and Worklets
Web Worker, Service Worker and Worklets
 
.Net Core
.Net Core.Net Core
.Net Core
 
Introducing Async/Await
Introducing Async/AwaitIntroducing Async/Await
Introducing Async/Await
 
Building blocks of Angular
Building blocks of AngularBuilding blocks of Angular
Building blocks of Angular
 
ReactJS presentation.pptx
ReactJS presentation.pptxReactJS presentation.pptx
ReactJS presentation.pptx
 
ES6 presentation
ES6 presentationES6 presentation
ES6 presentation
 
Introduction Node.js
Introduction Node.jsIntroduction Node.js
Introduction Node.js
 
Solid principles
Solid principlesSolid principles
Solid principles
 
Angular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP ServicesAngular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP Services
 
Testing Spring Boot Applications
Testing Spring Boot ApplicationsTesting Spring Boot Applications
Testing Spring Boot Applications
 

Similar to Asynchronous Programming in C# - Part 1

Background thread
Background threadBackground thread
Background thread
msarangam
 
Qtp 9.2 examples
Qtp 9.2 examplesQtp 9.2 examples
Qtp 9.2 examples
medsherb
 
Behavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWestBehavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWest
Joshua Warren
 

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

Background thread
Background threadBackground thread
Background thread
 
Qtp 9.2 examples
Qtp 9.2 examplesQtp 9.2 examples
Qtp 9.2 examples
 
Release with confidence
Release with confidenceRelease with confidence
Release with confidence
 
Architecture: Manual vs. Automation
Architecture: Manual vs. AutomationArchitecture: Manual vs. Automation
Architecture: Manual vs. Automation
 
What is selenium
What is seleniumWhat is selenium
What is selenium
 
Training – Going Async
Training – Going AsyncTraining – Going Async
Training – Going Async
 
C# 5 deep drive into asynchronous programming
C# 5 deep drive into asynchronous programmingC# 5 deep drive into asynchronous programming
C# 5 deep drive into asynchronous programming
 
Introduction of exception in vb.net
Introduction of exception in vb.netIntroduction of exception in vb.net
Introduction of exception in vb.net
 
Ddd melbourne 2011 C# async ctp
Ddd melbourne 2011  C# async ctpDdd melbourne 2011  C# async ctp
Ddd melbourne 2011 C# async ctp
 
Tdd is not about testing
Tdd is not about testingTdd is not about testing
Tdd is not about testing
 
Salesforce Apex Hours:-Mitigate with Mono-Purpose Microservices
Salesforce Apex Hours:-Mitigate with Mono-Purpose MicroservicesSalesforce Apex Hours:-Mitigate with Mono-Purpose Microservices
Salesforce Apex Hours:-Mitigate with Mono-Purpose Microservices
 
No Hugging, No Learning
No Hugging, No LearningNo Hugging, No Learning
No Hugging, No Learning
 
JAVASCRIPT Test Driven Development & Jasmine
JAVASCRIPT Test Driven Development & JasmineJAVASCRIPT Test Driven Development & Jasmine
JAVASCRIPT Test Driven Development & Jasmine
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Code
 
DevOps: The New Face Of Application Development - Global Azure Bootcamp
DevOps: The New Face Of Application Development - Global Azure BootcampDevOps: The New Face Of Application Development - Global Azure Bootcamp
DevOps: The New Face Of Application Development - Global Azure Bootcamp
 
Behavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWestBehavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWest
 
Why test with flex unit
Why test with flex unitWhy test with flex unit
Why test with flex unit
 
London SF Developers: Custom Lightning Component Error Handling
London SF Developers: Custom Lightning Component Error HandlingLondon SF Developers: Custom Lightning Component Error Handling
London SF Developers: Custom Lightning Component Error Handling
 
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
 
Introduction To Programming IP5
Introduction To Programming IP5Introduction To Programming IP5
Introduction To Programming IP5
 

More from Mindfire Solutions

More from Mindfire Solutions (20)

Physician Search and Review
Physician Search and ReviewPhysician Search and Review
Physician Search and Review
 
diet management app
diet management appdiet management app
diet management app
 
Business Technology Solution
Business Technology SolutionBusiness Technology Solution
Business Technology Solution
 
Remote Health Monitoring
Remote Health MonitoringRemote Health Monitoring
Remote Health Monitoring
 
Influencer Marketing Solution
Influencer Marketing SolutionInfluencer Marketing Solution
Influencer Marketing Solution
 
ELMAH
ELMAHELMAH
ELMAH
 
High Availability of Azure Applications
High Availability of Azure ApplicationsHigh Availability of Azure Applications
High Availability of Azure Applications
 
IOT Hands On
IOT Hands OnIOT Hands On
IOT Hands On
 
Glimpse of Loops Vs Set
Glimpse of Loops Vs SetGlimpse of Loops Vs Set
Glimpse of Loops Vs Set
 
Oracle Sql Developer-Getting Started
Oracle Sql Developer-Getting StartedOracle Sql Developer-Getting Started
Oracle Sql Developer-Getting Started
 
Adaptive Layout In iOS 8
Adaptive Layout In iOS 8Adaptive Layout In iOS 8
Adaptive Layout In iOS 8
 
Introduction to Auto-layout : iOS/Mac
Introduction to Auto-layout : iOS/MacIntroduction to Auto-layout : iOS/Mac
Introduction to Auto-layout : iOS/Mac
 
LINQPad - utility Tool
LINQPad - utility ToolLINQPad - utility Tool
LINQPad - utility Tool
 
Get started with watch kit development
Get started with watch kit developmentGet started with watch kit development
Get started with watch kit development
 
Swift vs Objective-C
Swift vs Objective-CSwift vs Objective-C
Swift vs Objective-C
 
Material Design in Android
Material Design in AndroidMaterial Design in Android
Material Design in Android
 
Introduction to OData
Introduction to ODataIntroduction to OData
Introduction to OData
 
Ext js Part 2- MVC
Ext js Part 2- MVCExt js Part 2- MVC
Ext js Part 2- MVC
 
ExtJs Basic Part-1
ExtJs Basic Part-1ExtJs Basic Part-1
ExtJs Basic Part-1
 
Spring Security Introduction
Spring Security IntroductionSpring Security Introduction
Spring Security Introduction
 

Recently uploaded

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Recently uploaded (20)

How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 

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