SlideShare a Scribd company logo
Asynchronous Programming
Demystified
1/14/2015
http://submain.com/webcasts/asynchronous-programming-demystified/
for the webcast recording, slides and demo code download
Webcast Housekeeping
1/14/2015
Audio
 Connect viaVoIP
 Plug in a headset or turn up your speakers
 Connect via Phone
 Select “UseTelephone” after joining the webinar
 Call 1 (415) 655-0053
Access Code: 805-361-561
Audio PIN: Shown after joining the webinar
Asking A Question
 Use the Questions window in the panel on the right of your screen
 Questions will be addressed at the end of the webcast
Recording
 A recording download link will be sent to all registrants within a few days
Copyright © SubMain 2015 2
Agenda
1/14/2015
 Overview of Async Patterns
 Introduction to async/await
 Asynchrony and Parallelism
 Benefits of async/await
 Demo
 Future Async webinars
 Q&A
Copyright © SubMain 2015 3
Introduction
Presenter
Stephen Cleary
Microsoft MVP
(g)host
Serge Baranovsky
Principal, SubMain
1/14/2015 Copyright © SubMain 2015 4
Stephen Cleary
stephencleary.com
C# Microsoft MVP
Concurrency in C# Cookbook (O’Reilly)
1/14/2015 Copyright © SubMain 2015 5
Introduction to async/await
1/14/2015 Copyright © SubMain 2015 6
Overview of Async Patterns
Async/await use theTask-basedAsync Pattern (TAP)
 Task SampleAsync();
Older: Event-based Async Pattern (EAP)
 void SampleAsync();
 event SampleCompleted;
Older: Async Programming Model (APM)
 IAsyncResult BeginSample();
 EndSample();
1/14/2015 Copyright © SubMain 2015 7
Syntax
Pair of keywords (async + await)
1/14/2015
int Test()
{
Thread.Sleep(100);
return 13;
}
async Task<int> TestAsync()
{
await Task.Delay(100);
return 13;
}
Copyright © SubMain 2015 8
What “async” means
Enables the await keyword in that method.
Creates a state machine for the method.
1/14/2015
async Task<int> TestAsync()
{
await Task.Delay(100);
return 13;
}
Copyright © SubMain 2015 9
What “await” means
An await expression takes one argument – an
“awaitable” (usually aTask orTask<T>).
 This “awaitable” represents an asynchronous operation.
1/14/2015
async Task<int> TestAsync()
{
await Task.Delay(100);
return 13;
}
Copyright © SubMain 2015 10
async Task<int> TestAsync()
{
var delayTask = Task.Delay(100);
await delayTask;
return 13;
}
What “await” means
Await will pause its async method until the operation
completes.
 If operation is already completed -> don’t pause.
 If operation faults -> raise exception.
Resume executing in a captured context by default.
1/14/2015
async Task<int> TestAsync()
{
await Task.Delay(100);
return 13;
}
Copyright © SubMain 2015 11
What “await” means
When await pauses:
 Returns an incomplete task to its caller.
When async method completes:
 Completes the task that was returned earlier.
The task represents the method.
1/14/2015
async Task<int> TestAsync()
{
await Task.Delay(100);
return 13;
}
Copyright © SubMain 2015 12
Captured Context
When await resumes:
 SynchronizationContext.Current orTaskScheduler.Current
What that means in practice:
 UI context, ASP.NET request context, or thread pool.
Avoiding context: use ConfigureAwait(false).
1/14/2015
async Task<int> TestAsync()
{
await Task.Delay(100);
return 13;
}
Copyright © SubMain 2015 13
What “await” doesn’t mean
Nothing to do with threads.
 Not at all like “asynchronous delegates”.
 Does not run the code on a background thread.
 Does not parallelize your code.
1/14/2015
async Task<int> TestAsync()
{
await Task.Delay(100);
return 13;
}
Copyright © SubMain 2015 14
Asynchrony != Parallelism
Each have their uses.
 Asynchrony – I/O, events.
 Parallelism – CPU-bound processing.
1/14/2015 Copyright © SubMain 2015 15
Concurrency
Asynchrony Parallelism
Benefits of async/await
 Responsiveness on the client side
 Scalability on the server side
 Naturally-asynchronous code has async APIs
 Naturally-synchronous code stays synchronous
 Asynchronous code is clean – no callbacks!
1/14/2015 Copyright © SubMain 2015 16
What is CodeIt.Right
1/14/2015 Copyright © SubMain 2015 17
What is CodeIt.Right
 Code Quality Analysis and Metrics
 Automated Code Review process
 Automated way to discover and
fix code smells
 Automatic and safe refactoring
of issues into conforming code
 Ensure your code adheres to
(your) predefined design
requirements and best coding
practices
1/14/2015 Copyright © SubMain 2015 18
What is CodeIt.Right - continued
Instant Code Review – real-time code checking
OnDemand Analysis
Source Control Check-In Policy
Build Process Integration
Hundreds of rules
 Security, Performance, Usage,
Design, Maintainability,
Exception Handling, Globalization,
Async, and more
1/14/2015 Copyright © SubMain 2015 19
Demo
Demo #1 – Correct async code
Demo #2 – Async naming convention
Demo #3 – Async void
Demo #4 – Blocking on async code
Demo #5 – Async code blocking
Demo #6 – Fake-async code
Demo #7 – Using ContinueWith
1/14/2015 Copyright © SubMain 2015 20
http://submain.com/webcasts/asynchronous-programming-demystified/
for the webcast recording, slides and demo code download
Asynchronous Programming
Async confusing? CodeIt.Right will guide
 CodeIt.Right Async rule set:
 Async method should have "Async" suffix
 Async method should have await statement
 Async method should returnTask orTask<T>
 Async method - avoid "out" and "ref" parameters
 Async method - await for completion
 Await statement - method should be async
 Async method - call Start on theTask
 Async method - do not useTask.Yield
 Async method - do not useTask.Wait
 Async method should not be Sub
 Async method parameters should be the same to synchronous counterpart
 Async method - transform to non-async if simple
1/14/2015 Copyright © SubMain 2015 22
Poll
 Future Async webinars
1/14/2015 Copyright © SubMain 2015 23
Q&A
Questions?
Email - customer-service@submain.com
Video - submain.com/codeit.right/video
Download the free CodeIt.Right trial at submain.com/codeit.right
Contact Stephen Cleary: stephencleary.com
1/14/2015
1 (800) 936-2134
Copyright © SubMain 2015 24
http://submain.com/webcasts/asynchronous-programming-demystified/
for the webcast recording, slides and demo code download

More Related Content

Viewers also liked

Asynchronous programming
Asynchronous programmingAsynchronous programming
Asynchronous programmingChester Hartin
 
Code Refactoring
Code RefactoringCode Refactoring
Code Refactoring
Charlie Berg
 
Refactor your Java EE application using Microservices and Containers - Arun G...
Refactor your Java EE application using Microservices and Containers - Arun G...Refactor your Java EE application using Microservices and Containers - Arun G...
Refactor your Java EE application using Microservices and Containers - Arun G...
Codemotion
 
Refactoring 101
Refactoring 101Refactoring 101
Refactoring 101
Adam Culp
 
Refactoring - An Introduction
Refactoring - An IntroductionRefactoring - An Introduction
Refactoring - An Introduction
Giorgio Vespucci
 
Refactoring Tips by Martin Fowler
Refactoring Tips by Martin FowlerRefactoring Tips by Martin Fowler
Refactoring Tips by Martin Fowler
Igor Crvenov
 
Refactoring: Improve the design of existing code
Refactoring: Improve the design of existing codeRefactoring: Improve the design of existing code
Refactoring: Improve the design of existing code
Valerio Maggio
 

Viewers also liked (7)

Asynchronous programming
Asynchronous programmingAsynchronous programming
Asynchronous programming
 
Code Refactoring
Code RefactoringCode Refactoring
Code Refactoring
 
Refactor your Java EE application using Microservices and Containers - Arun G...
Refactor your Java EE application using Microservices and Containers - Arun G...Refactor your Java EE application using Microservices and Containers - Arun G...
Refactor your Java EE application using Microservices and Containers - Arun G...
 
Refactoring 101
Refactoring 101Refactoring 101
Refactoring 101
 
Refactoring - An Introduction
Refactoring - An IntroductionRefactoring - An Introduction
Refactoring - An Introduction
 
Refactoring Tips by Martin Fowler
Refactoring Tips by Martin FowlerRefactoring Tips by Martin Fowler
Refactoring Tips by Martin Fowler
 
Refactoring: Improve the design of existing code
Refactoring: Improve the design of existing codeRefactoring: Improve the design of existing code
Refactoring: Improve the design of existing code
 

Similar to Webcast: Asynchronous Programming Demystified

Bangalore Cloud Foundry meetup - Mani
Bangalore Cloud Foundry meetup - ManiBangalore Cloud Foundry meetup - Mani
Bangalore Cloud Foundry meetup - Mani
Mani Chandrasekaran
 
Tune your App Perf (and get fit for summer)
Tune your App Perf (and get fit for summer)Tune your App Perf (and get fit for summer)
Tune your App Perf (and get fit for summer)
Sqreen
 
Webinar: OpenStack Best Practices for Production
Webinar: OpenStack Best Practices for ProductionWebinar: OpenStack Best Practices for Production
Webinar: OpenStack Best Practices for Production
Platform9
 
Mobile App Quality Roadmap for DevTest Teams
Mobile App Quality Roadmap for DevTest TeamsMobile App Quality Roadmap for DevTest Teams
Mobile App Quality Roadmap for DevTest Teams
Perfecto by Perforce
 
API Force Presentation
API Force PresentationAPI Force Presentation
API Force Presentation
Amir Khan
 
Advanced Strategies for Testing Responsive Web
Advanced Strategies for Testing Responsive WebAdvanced Strategies for Testing Responsive Web
Advanced Strategies for Testing Responsive Web
Perfecto by Perforce
 
[2015-11월 정기 세미나] Cloud Native Platform - Pivotal
[2015-11월 정기 세미나] Cloud Native Platform - Pivotal[2015-11월 정기 세미나] Cloud Native Platform - Pivotal
[2015-11월 정기 세미나] Cloud Native Platform - Pivotal
OpenStack Korea Community
 
Sustainability Challenge, Postman, Rest sheet and Anypoint provider : MuleSof...
Sustainability Challenge, Postman, Rest sheet and Anypoint provider : MuleSof...Sustainability Challenge, Postman, Rest sheet and Anypoint provider : MuleSof...
Sustainability Challenge, Postman, Rest sheet and Anypoint provider : MuleSof...
Angel Alberici
 
Real World Problem Solving Using Application Performance Management 10
Real World Problem Solving Using Application Performance Management 10Real World Problem Solving Using Application Performance Management 10
Real World Problem Solving Using Application Performance Management 10
CA Technologies
 
Continuous Delivery with a PaaS Application
Continuous Delivery with a PaaS ApplicationContinuous Delivery with a PaaS Application
Continuous Delivery with a PaaS Application
Mark Rendell
 
Node.js primer for ITE students
Node.js primer for ITE studentsNode.js primer for ITE students
Node.js primer for ITE students
Quhan Arunasalam
 
Continuous Delivery Agiles 2014 Medellin
Continuous Delivery Agiles 2014 MedellinContinuous Delivery Agiles 2014 Medellin
Continuous Delivery Agiles 2014 Medellin
Diego Garber
 
Continuous Delivery for IT Operations Teams
Continuous Delivery for IT Operations TeamsContinuous Delivery for IT Operations Teams
Continuous Delivery for IT Operations Teams
Mark Rendell
 
Test Automation at the Speed of Agile: Making It Work Every Build
Test Automation at the Speed of Agile: Making It Work Every BuildTest Automation at the Speed of Agile: Making It Work Every Build
Test Automation at the Speed of Agile: Making It Work Every Build
TechWell
 
Anatomy of a Build Pipeline
Anatomy of a Build PipelineAnatomy of a Build Pipeline
Anatomy of a Build Pipeline
Samuel Brown
 
Making Security Agile
Making Security AgileMaking Security Agile
Making Security Agile
Oleg Gryb
 
MuleSoft Meetup Virtual_ 2_Charlotte
MuleSoft Meetup Virtual_ 2_CharlotteMuleSoft Meetup Virtual_ 2_Charlotte
MuleSoft Meetup Virtual_ 2_Charlotte
Subhash Patel
 
Reduce Software Release Cycles by 4-5x with Application Release Automation fo...
Reduce Software Release Cycles by 4-5x with Application Release Automation fo...Reduce Software Release Cycles by 4-5x with Application Release Automation fo...
Reduce Software Release Cycles by 4-5x with Application Release Automation fo...
CA Technologies
 
Maximize the power of OSGi in AEM
Maximize the power of OSGi in AEM Maximize the power of OSGi in AEM
Maximize the power of OSGi in AEM
ICF CIRCUIT
 
Discover the real user experience with Alyvix - Icinga Camp Milan 2019
Discover the real user experience with Alyvix - Icinga Camp Milan 2019Discover the real user experience with Alyvix - Icinga Camp Milan 2019
Discover the real user experience with Alyvix - Icinga Camp Milan 2019
Icinga
 

Similar to Webcast: Asynchronous Programming Demystified (20)

Bangalore Cloud Foundry meetup - Mani
Bangalore Cloud Foundry meetup - ManiBangalore Cloud Foundry meetup - Mani
Bangalore Cloud Foundry meetup - Mani
 
Tune your App Perf (and get fit for summer)
Tune your App Perf (and get fit for summer)Tune your App Perf (and get fit for summer)
Tune your App Perf (and get fit for summer)
 
Webinar: OpenStack Best Practices for Production
Webinar: OpenStack Best Practices for ProductionWebinar: OpenStack Best Practices for Production
Webinar: OpenStack Best Practices for Production
 
Mobile App Quality Roadmap for DevTest Teams
Mobile App Quality Roadmap for DevTest TeamsMobile App Quality Roadmap for DevTest Teams
Mobile App Quality Roadmap for DevTest Teams
 
API Force Presentation
API Force PresentationAPI Force Presentation
API Force Presentation
 
Advanced Strategies for Testing Responsive Web
Advanced Strategies for Testing Responsive WebAdvanced Strategies for Testing Responsive Web
Advanced Strategies for Testing Responsive Web
 
[2015-11월 정기 세미나] Cloud Native Platform - Pivotal
[2015-11월 정기 세미나] Cloud Native Platform - Pivotal[2015-11월 정기 세미나] Cloud Native Platform - Pivotal
[2015-11월 정기 세미나] Cloud Native Platform - Pivotal
 
Sustainability Challenge, Postman, Rest sheet and Anypoint provider : MuleSof...
Sustainability Challenge, Postman, Rest sheet and Anypoint provider : MuleSof...Sustainability Challenge, Postman, Rest sheet and Anypoint provider : MuleSof...
Sustainability Challenge, Postman, Rest sheet and Anypoint provider : MuleSof...
 
Real World Problem Solving Using Application Performance Management 10
Real World Problem Solving Using Application Performance Management 10Real World Problem Solving Using Application Performance Management 10
Real World Problem Solving Using Application Performance Management 10
 
Continuous Delivery with a PaaS Application
Continuous Delivery with a PaaS ApplicationContinuous Delivery with a PaaS Application
Continuous Delivery with a PaaS Application
 
Node.js primer for ITE students
Node.js primer for ITE studentsNode.js primer for ITE students
Node.js primer for ITE students
 
Continuous Delivery Agiles 2014 Medellin
Continuous Delivery Agiles 2014 MedellinContinuous Delivery Agiles 2014 Medellin
Continuous Delivery Agiles 2014 Medellin
 
Continuous Delivery for IT Operations Teams
Continuous Delivery for IT Operations TeamsContinuous Delivery for IT Operations Teams
Continuous Delivery for IT Operations Teams
 
Test Automation at the Speed of Agile: Making It Work Every Build
Test Automation at the Speed of Agile: Making It Work Every BuildTest Automation at the Speed of Agile: Making It Work Every Build
Test Automation at the Speed of Agile: Making It Work Every Build
 
Anatomy of a Build Pipeline
Anatomy of a Build PipelineAnatomy of a Build Pipeline
Anatomy of a Build Pipeline
 
Making Security Agile
Making Security AgileMaking Security Agile
Making Security Agile
 
MuleSoft Meetup Virtual_ 2_Charlotte
MuleSoft Meetup Virtual_ 2_CharlotteMuleSoft Meetup Virtual_ 2_Charlotte
MuleSoft Meetup Virtual_ 2_Charlotte
 
Reduce Software Release Cycles by 4-5x with Application Release Automation fo...
Reduce Software Release Cycles by 4-5x with Application Release Automation fo...Reduce Software Release Cycles by 4-5x with Application Release Automation fo...
Reduce Software Release Cycles by 4-5x with Application Release Automation fo...
 
Maximize the power of OSGi in AEM
Maximize the power of OSGi in AEM Maximize the power of OSGi in AEM
Maximize the power of OSGi in AEM
 
Discover the real user experience with Alyvix - Icinga Camp Milan 2019
Discover the real user experience with Alyvix - Icinga Camp Milan 2019Discover the real user experience with Alyvix - Icinga Camp Milan 2019
Discover the real user experience with Alyvix - Icinga Camp Milan 2019
 

Recently uploaded

Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Jay Das
 

Recently uploaded (20)

Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
 

Webcast: Asynchronous Programming Demystified

  • 2. Webcast Housekeeping 1/14/2015 Audio  Connect viaVoIP  Plug in a headset or turn up your speakers  Connect via Phone  Select “UseTelephone” after joining the webinar  Call 1 (415) 655-0053 Access Code: 805-361-561 Audio PIN: Shown after joining the webinar Asking A Question  Use the Questions window in the panel on the right of your screen  Questions will be addressed at the end of the webcast Recording  A recording download link will be sent to all registrants within a few days Copyright © SubMain 2015 2
  • 3. Agenda 1/14/2015  Overview of Async Patterns  Introduction to async/await  Asynchrony and Parallelism  Benefits of async/await  Demo  Future Async webinars  Q&A Copyright © SubMain 2015 3
  • 4. Introduction Presenter Stephen Cleary Microsoft MVP (g)host Serge Baranovsky Principal, SubMain 1/14/2015 Copyright © SubMain 2015 4
  • 5. Stephen Cleary stephencleary.com C# Microsoft MVP Concurrency in C# Cookbook (O’Reilly) 1/14/2015 Copyright © SubMain 2015 5
  • 6. Introduction to async/await 1/14/2015 Copyright © SubMain 2015 6
  • 7. Overview of Async Patterns Async/await use theTask-basedAsync Pattern (TAP)  Task SampleAsync(); Older: Event-based Async Pattern (EAP)  void SampleAsync();  event SampleCompleted; Older: Async Programming Model (APM)  IAsyncResult BeginSample();  EndSample(); 1/14/2015 Copyright © SubMain 2015 7
  • 8. Syntax Pair of keywords (async + await) 1/14/2015 int Test() { Thread.Sleep(100); return 13; } async Task<int> TestAsync() { await Task.Delay(100); return 13; } Copyright © SubMain 2015 8
  • 9. What “async” means Enables the await keyword in that method. Creates a state machine for the method. 1/14/2015 async Task<int> TestAsync() { await Task.Delay(100); return 13; } Copyright © SubMain 2015 9
  • 10. What “await” means An await expression takes one argument – an “awaitable” (usually aTask orTask<T>).  This “awaitable” represents an asynchronous operation. 1/14/2015 async Task<int> TestAsync() { await Task.Delay(100); return 13; } Copyright © SubMain 2015 10 async Task<int> TestAsync() { var delayTask = Task.Delay(100); await delayTask; return 13; }
  • 11. What “await” means Await will pause its async method until the operation completes.  If operation is already completed -> don’t pause.  If operation faults -> raise exception. Resume executing in a captured context by default. 1/14/2015 async Task<int> TestAsync() { await Task.Delay(100); return 13; } Copyright © SubMain 2015 11
  • 12. What “await” means When await pauses:  Returns an incomplete task to its caller. When async method completes:  Completes the task that was returned earlier. The task represents the method. 1/14/2015 async Task<int> TestAsync() { await Task.Delay(100); return 13; } Copyright © SubMain 2015 12
  • 13. Captured Context When await resumes:  SynchronizationContext.Current orTaskScheduler.Current What that means in practice:  UI context, ASP.NET request context, or thread pool. Avoiding context: use ConfigureAwait(false). 1/14/2015 async Task<int> TestAsync() { await Task.Delay(100); return 13; } Copyright © SubMain 2015 13
  • 14. What “await” doesn’t mean Nothing to do with threads.  Not at all like “asynchronous delegates”.  Does not run the code on a background thread.  Does not parallelize your code. 1/14/2015 async Task<int> TestAsync() { await Task.Delay(100); return 13; } Copyright © SubMain 2015 14
  • 15. Asynchrony != Parallelism Each have their uses.  Asynchrony – I/O, events.  Parallelism – CPU-bound processing. 1/14/2015 Copyright © SubMain 2015 15 Concurrency Asynchrony Parallelism
  • 16. Benefits of async/await  Responsiveness on the client side  Scalability on the server side  Naturally-asynchronous code has async APIs  Naturally-synchronous code stays synchronous  Asynchronous code is clean – no callbacks! 1/14/2015 Copyright © SubMain 2015 16
  • 17. What is CodeIt.Right 1/14/2015 Copyright © SubMain 2015 17
  • 18. What is CodeIt.Right  Code Quality Analysis and Metrics  Automated Code Review process  Automated way to discover and fix code smells  Automatic and safe refactoring of issues into conforming code  Ensure your code adheres to (your) predefined design requirements and best coding practices 1/14/2015 Copyright © SubMain 2015 18
  • 19. What is CodeIt.Right - continued Instant Code Review – real-time code checking OnDemand Analysis Source Control Check-In Policy Build Process Integration Hundreds of rules  Security, Performance, Usage, Design, Maintainability, Exception Handling, Globalization, Async, and more 1/14/2015 Copyright © SubMain 2015 19
  • 20. Demo Demo #1 – Correct async code Demo #2 – Async naming convention Demo #3 – Async void Demo #4 – Blocking on async code Demo #5 – Async code blocking Demo #6 – Fake-async code Demo #7 – Using ContinueWith 1/14/2015 Copyright © SubMain 2015 20 http://submain.com/webcasts/asynchronous-programming-demystified/ for the webcast recording, slides and demo code download
  • 21. Asynchronous Programming Async confusing? CodeIt.Right will guide  CodeIt.Right Async rule set:  Async method should have "Async" suffix  Async method should have await statement  Async method should returnTask orTask<T>  Async method - avoid "out" and "ref" parameters  Async method - await for completion  Await statement - method should be async  Async method - call Start on theTask  Async method - do not useTask.Yield  Async method - do not useTask.Wait  Async method should not be Sub  Async method parameters should be the same to synchronous counterpart  Async method - transform to non-async if simple 1/14/2015 Copyright © SubMain 2015 22
  • 22. Poll  Future Async webinars 1/14/2015 Copyright © SubMain 2015 23
  • 23. Q&A Questions? Email - customer-service@submain.com Video - submain.com/codeit.right/video Download the free CodeIt.Right trial at submain.com/codeit.right Contact Stephen Cleary: stephencleary.com 1/14/2015 1 (800) 936-2134 Copyright © SubMain 2015 24 http://submain.com/webcasts/asynchronous-programming-demystified/ for the webcast recording, slides and demo code download