SlideShare uma empresa Scribd logo
1 de 11
J e f f H a r t
V a n i s h i n g C l o u d s , I n c .
Async/Await for Fun and Profit
Multithreading is just one damn thing after…
…before, or the simultaneously with another.
Scott Meyers and Andrei Alexandrescu
…before
March 7-8, 2015
Why Multithreading?
 “Modern” apps force multithreading
 Desktop/client – avoiding the “toilet bowl”
 Server-side scalability – all about the cores
 Economics – computers not faster since P4 (90nm)
Copyright © Jeff Hart, 2015
Know Your Goal
 Offloading – free the “main” thread
 Still uses another (Thread Pool) thread
 Works for CPU bound (i.e., thread backed)
 Scaling – not using “any” thread
 Still uses IO completion ports
 Only works for IO bound provided by “framework”
Copyright © Jeff Hart, 2015
Domain: Prime Numbers
 Natural numbers c only divisible by itself and 1
for(int d=2; d<c-1; d++)…
 Only even prime is 2
for(int d=3; d<c-1; d+=2)…
 If c/d = q, then c/q = d; and q or d ≤ SQRT(c)
for(int d=3; d<=Math.Sqrt(c); d+=2)…
 If c/d, then d is a prime or divisible by one<d
So only test against previously found primes
… lots of more powerful sieves
Copyright © Jeff Hart, 2015
Basic ROT
 await converts Task<T> to <T> (Task to void)
 Using await  changing signature: async Task[<T>]
 Warning on async method w/o using await
 Can’t await in catch/finally or lock
 Can’t make properties async
 Method returns Task<T>, but you return T;
 If you have used await
 Never call async void (event handlers only)
Copyright © Jeff Hart, 2015
Floor to Ceiling
 Go down to:
 Framework XxxAsync for scaling
 “Creating” asynchronicity
Task.Run( { … } ) way better than worker threads
 Go up to:
 Handler
 MSTest, etc.
 “Eating” asynchronicity
task.ContinueWith( …, TaskContinuationOptions.Only|Not)
task.Result - blocks
Copyright © Jeff Hart, 2015
We’ve Been At This…
 CLR v1: APM – Async Programming Model
 Simple (mechanical) but limiting
 CLR v2: EAP – Event-based Asynchronous Pattern
 Very flexible but lots of “namespace noise”
 CLR v4: TAP – Task-based Asynchronous Pattern
 V4.5 async/await “complier sugar”
Copyright © Jeff Hart, 2015
Getting Real (Data)
 Entity Framework 6 is TAP enabled
 Secret: using System.Data.Entity;
 All|AnyAsync
 Count|Average|Sum|Min|MaxAsync
 ContainsAsync
 First|Single[OrDefault]Async
 ForEachAsync
 LoadAsync
 ToArray|List|DictionaryAsync
Copyright © Jeff Hart, 2015
Graduation
foreach( var d in GetLotsOfData() ){
DoSomethingReallyLong(d);
}
Parallel.ForEach( GetLotsOfData(), d=>{
DoSomethingReallyLong(d);
}
var tasks = new List<Task>()
foreach( var d in GetLotsOfData() ){
tasks.Add(DoSomethingReallyLongAsync(d));
}
Task.AwaitAll(tasks);
?
Copyright © Jeff Hart, 2015
Layers of Multithreading
 Async/await two-step
 Separating task and await
 Knowin’ when to make ‘em;
And knowin’ when to tend ‘em
 Rules of Thumb
 Mostly compiler enforced/assisted
 Avoid async void (fire and forget)
 Go “floor to ceiling” when possible
 Task’s members to “stop”
 TaskCompletionSource to “create”
The scary bit:
Synchronizing (data)
Copyright © Jeff Hart, 2015
SpeakerRate.com
• Search for “async” or “socalcodecamp”
• h t t p : / / s p e a k e r r a t e . c o m / t a l k s / 4 9 3 2 1 - s o c a l c o d e c a m p -
i n t r o - t o - a s y n c - a w a i t
Thank YOU!
Copyright © Jeff Hart, 2015
17

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Reactive Programming in Java 8 with Rx-Java
Reactive Programming in Java 8 with Rx-JavaReactive Programming in Java 8 with Rx-Java
Reactive Programming in Java 8 with Rx-Java
 
Introduction Node.js
Introduction Node.jsIntroduction Node.js
Introduction Node.js
 
Java And Multithreading
Java And MultithreadingJava And Multithreading
Java And Multithreading
 
Clean architecture
Clean architectureClean architecture
Clean architecture
 
Introduction to .NET Core
Introduction to .NET CoreIntroduction to .NET Core
Introduction to .NET Core
 
RxJava - introduction & design
RxJava - introduction & designRxJava - introduction & design
RxJava - introduction & design
 
Sync, async and multithreading
Sync, async and multithreadingSync, async and multithreading
Sync, async and multithreading
 
Asynchronous programming
Asynchronous programmingAsynchronous programming
Asynchronous programming
 
rx-java-presentation
rx-java-presentationrx-java-presentation
rx-java-presentation
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
SOLID Principles and The Clean Architecture
SOLID Principles and The Clean ArchitectureSOLID Principles and The Clean Architecture
SOLID Principles and The Clean Architecture
 
React Components Lifecycle | React Tutorial for Beginners | ReactJS Training ...
React Components Lifecycle | React Tutorial for Beginners | ReactJS Training ...React Components Lifecycle | React Tutorial for Beginners | ReactJS Training ...
React Components Lifecycle | React Tutorial for Beginners | ReactJS Training ...
 
Android | Android Activity Launch Modes and Tasks | Gonçalo Silva
Android | Android Activity Launch Modes and Tasks | Gonçalo SilvaAndroid | Android Activity Launch Modes and Tasks | Gonçalo Silva
Android | Android Activity Launch Modes and Tasks | Gonçalo Silva
 
Asynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & PromisesAsynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & Promises
 
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
 
Solid principles
Solid principlesSolid principles
Solid principles
 
Java spring ppt
Java spring pptJava spring ppt
Java spring ppt
 
Using hilt in a modularized project
Using hilt in a modularized projectUsing hilt in a modularized project
Using hilt in a modularized project
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
 

Destaque

CTU June 2011 - C# 5.0 - ASYNC & Await
CTU June 2011 - C# 5.0 - ASYNC & AwaitCTU June 2011 - C# 5.0 - ASYNC & Await
CTU June 2011 - C# 5.0 - ASYNC & Await
Spiffy
 
Async in .NET
Async in .NETAsync in .NET
Async in .NET
RTigger
 
Using Async in your Mobile Apps - Marek Safar
Using Async in your Mobile Apps - Marek SafarUsing Async in your Mobile Apps - Marek Safar
Using Async in your Mobile Apps - Marek Safar
Xamarin
 
transmisión de datos, detección y corrección de errores y compresión de datos
transmisión de datos, detección y corrección de errores y compresión de datostransmisión de datos, detección y corrección de errores y compresión de datos
transmisión de datos, detección y corrección de errores y compresión de datos
edithvelasquez
 
C# Delegates and Event Handling
C# Delegates and Event HandlingC# Delegates and Event Handling
C# Delegates and Event Handling
Jussi Pohjolainen
 
Presentacion grafica de la configuarcion de una red punto a punto
Presentacion grafica de la configuarcion de una red punto a puntoPresentacion grafica de la configuarcion de una red punto a punto
Presentacion grafica de la configuarcion de una red punto a punto
dany alexis
 

Destaque (14)

Async await
Async awaitAsync await
Async await
 
Modos de transmisión
Modos de transmisión Modos de transmisión
Modos de transmisión
 
CTU June 2011 - C# 5.0 - ASYNC & Await
CTU June 2011 - C# 5.0 - ASYNC & AwaitCTU June 2011 - C# 5.0 - ASYNC & Await
CTU June 2011 - C# 5.0 - ASYNC & Await
 
Async / Await: Programación asíncrona para dummies (12 horas visual studio)
Async / Await: Programación asíncrona para dummies (12 horas visual studio)Async / Await: Programación asíncrona para dummies (12 horas visual studio)
Async / Await: Programación asíncrona para dummies (12 horas visual studio)
 
Async in .NET
Async in .NETAsync in .NET
Async in .NET
 
Asynchronous programming from Xamarin Hakcday in Melbourne
Asynchronous programming from Xamarin Hakcday in MelbourneAsynchronous programming from Xamarin Hakcday in Melbourne
Asynchronous programming from Xamarin Hakcday in Melbourne
 
Evolution of C# delegates
Evolution of C# delegatesEvolution of C# delegates
Evolution of C# delegates
 
Using Async in your Mobile Apps - Marek Safar
Using Async in your Mobile Apps - Marek SafarUsing Async in your Mobile Apps - Marek Safar
Using Async in your Mobile Apps - Marek Safar
 
C#을 이용한 task 병렬화와 비동기 패턴
C#을 이용한 task 병렬화와 비동기 패턴C#을 이용한 task 병렬화와 비동기 패턴
C#을 이용한 task 병렬화와 비동기 패턴
 
transmisión de datos, detección y corrección de errores y compresión de datos
transmisión de datos, detección y corrección de errores y compresión de datostransmisión de datos, detección y corrección de errores y compresión de datos
transmisión de datos, detección y corrección de errores y compresión de datos
 
Estructura del Internet, redes lan, man y wan, módems.
Estructura del Internet, redes lan, man y wan, módems.Estructura del Internet, redes lan, man y wan, módems.
Estructura del Internet, redes lan, man y wan, módems.
 
C# Delegates and Event Handling
C# Delegates and Event HandlingC# Delegates and Event Handling
C# Delegates and Event Handling
 
C# Delegates
C# DelegatesC# Delegates
C# Delegates
 
Presentacion grafica de la configuarcion de una red punto a punto
Presentacion grafica de la configuarcion de una red punto a puntoPresentacion grafica de la configuarcion de una red punto a punto
Presentacion grafica de la configuarcion de una red punto a punto
 

Semelhante a Async/Await

Concurrent Programming OpenMP @ Distributed System Discussion
Concurrent Programming OpenMP @ Distributed System DiscussionConcurrent Programming OpenMP @ Distributed System Discussion
Concurrent Programming OpenMP @ Distributed System Discussion
CherryBerry2
 
Unmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/InvokeUnmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/Invoke
Dmitri Nesteruk
 
Threaded Programming
Threaded ProgrammingThreaded Programming
Threaded Programming
Sri Prasanna
 
Apache Flink@ Strata & Hadoop World London
Apache Flink@ Strata & Hadoop World LondonApache Flink@ Strata & Hadoop World London
Apache Flink@ Strata & Hadoop World London
Stephan Ewen
 

Semelhante a Async/Await (20)

Migration To Multi Core - Parallel Programming Models
Migration To Multi Core - Parallel Programming ModelsMigration To Multi Core - Parallel Programming Models
Migration To Multi Core - Parallel Programming Models
 
Everyone loves PHP
Everyone loves PHPEveryone loves PHP
Everyone loves PHP
 
Overview Of Parallel Development - Ericnel
Overview Of Parallel Development -  EricnelOverview Of Parallel Development -  Ericnel
Overview Of Parallel Development - Ericnel
 
Better Code: Concurrency
Better Code: ConcurrencyBetter Code: Concurrency
Better Code: Concurrency
 
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
 
Concurrent Programming OpenMP @ Distributed System Discussion
Concurrent Programming OpenMP @ Distributed System DiscussionConcurrent Programming OpenMP @ Distributed System Discussion
Concurrent Programming OpenMP @ Distributed System Discussion
 
High-Performance Computing and OpenSolaris
High-Performance Computing and OpenSolarisHigh-Performance Computing and OpenSolaris
High-Performance Computing and OpenSolaris
 
parallel-computation.pdf
parallel-computation.pdfparallel-computation.pdf
parallel-computation.pdf
 
Programming 1 [compatibility mode]mm
Programming 1 [compatibility mode]mmProgramming 1 [compatibility mode]mm
Programming 1 [compatibility mode]mm
 
Parallel computation
Parallel computationParallel computation
Parallel computation
 
C++ Coroutines
C++ CoroutinesC++ Coroutines
C++ Coroutines
 
Unmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/InvokeUnmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/Invoke
 
Asynchronous programming - .NET Way
Asynchronous programming - .NET WayAsynchronous programming - .NET Way
Asynchronous programming - .NET Way
 
Threaded Programming
Threaded ProgrammingThreaded Programming
Threaded Programming
 
Comparison of various streaming technologies
Comparison of various streaming technologiesComparison of various streaming technologies
Comparison of various streaming technologies
 
Apache Flink@ Strata & Hadoop World London
Apache Flink@ Strata & Hadoop World LondonApache Flink@ Strata & Hadoop World London
Apache Flink@ Strata & Hadoop World London
 
How to deploy & optimize eZ Publish
How to deploy & optimize eZ PublishHow to deploy & optimize eZ Publish
How to deploy & optimize eZ Publish
 
Introduction to HPC Programming Models - EUDAT Summer School (Stefano Markidi...
Introduction to HPC Programming Models - EUDAT Summer School (Stefano Markidi...Introduction to HPC Programming Models - EUDAT Summer School (Stefano Markidi...
Introduction to HPC Programming Models - EUDAT Summer School (Stefano Markidi...
 
SequenceL Auto-Parallelizing Toolset Intro slideshare
SequenceL Auto-Parallelizing Toolset Intro slideshareSequenceL Auto-Parallelizing Toolset Intro slideshare
SequenceL Auto-Parallelizing Toolset Intro slideshare
 
SequenceL intro slideshare
SequenceL intro slideshareSequenceL intro slideshare
SequenceL intro slideshare
 

Último

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
+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
 

Último (20)

Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
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-...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
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
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
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
 
+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...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 

Async/Await

  • 1. J e f f H a r t V a n i s h i n g C l o u d s , I n c . Async/Await for Fun and Profit Multithreading is just one damn thing after… …before, or the simultaneously with another. Scott Meyers and Andrei Alexandrescu …before March 7-8, 2015
  • 2. Why Multithreading?  “Modern” apps force multithreading  Desktop/client – avoiding the “toilet bowl”  Server-side scalability – all about the cores  Economics – computers not faster since P4 (90nm) Copyright © Jeff Hart, 2015
  • 3. Know Your Goal  Offloading – free the “main” thread  Still uses another (Thread Pool) thread  Works for CPU bound (i.e., thread backed)  Scaling – not using “any” thread  Still uses IO completion ports  Only works for IO bound provided by “framework” Copyright © Jeff Hart, 2015
  • 4. Domain: Prime Numbers  Natural numbers c only divisible by itself and 1 for(int d=2; d<c-1; d++)…  Only even prime is 2 for(int d=3; d<c-1; d+=2)…  If c/d = q, then c/q = d; and q or d ≤ SQRT(c) for(int d=3; d<=Math.Sqrt(c); d+=2)…  If c/d, then d is a prime or divisible by one<d So only test against previously found primes … lots of more powerful sieves Copyright © Jeff Hart, 2015
  • 5. Basic ROT  await converts Task<T> to <T> (Task to void)  Using await  changing signature: async Task[<T>]  Warning on async method w/o using await  Can’t await in catch/finally or lock  Can’t make properties async  Method returns Task<T>, but you return T;  If you have used await  Never call async void (event handlers only) Copyright © Jeff Hart, 2015
  • 6. Floor to Ceiling  Go down to:  Framework XxxAsync for scaling  “Creating” asynchronicity Task.Run( { … } ) way better than worker threads  Go up to:  Handler  MSTest, etc.  “Eating” asynchronicity task.ContinueWith( …, TaskContinuationOptions.Only|Not) task.Result - blocks Copyright © Jeff Hart, 2015
  • 7. We’ve Been At This…  CLR v1: APM – Async Programming Model  Simple (mechanical) but limiting  CLR v2: EAP – Event-based Asynchronous Pattern  Very flexible but lots of “namespace noise”  CLR v4: TAP – Task-based Asynchronous Pattern  V4.5 async/await “complier sugar” Copyright © Jeff Hart, 2015
  • 8. Getting Real (Data)  Entity Framework 6 is TAP enabled  Secret: using System.Data.Entity;  All|AnyAsync  Count|Average|Sum|Min|MaxAsync  ContainsAsync  First|Single[OrDefault]Async  ForEachAsync  LoadAsync  ToArray|List|DictionaryAsync Copyright © Jeff Hart, 2015
  • 9. Graduation foreach( var d in GetLotsOfData() ){ DoSomethingReallyLong(d); } Parallel.ForEach( GetLotsOfData(), d=>{ DoSomethingReallyLong(d); } var tasks = new List<Task>() foreach( var d in GetLotsOfData() ){ tasks.Add(DoSomethingReallyLongAsync(d)); } Task.AwaitAll(tasks); ? Copyright © Jeff Hart, 2015
  • 10. Layers of Multithreading  Async/await two-step  Separating task and await  Knowin’ when to make ‘em; And knowin’ when to tend ‘em  Rules of Thumb  Mostly compiler enforced/assisted  Avoid async void (fire and forget)  Go “floor to ceiling” when possible  Task’s members to “stop”  TaskCompletionSource to “create” The scary bit: Synchronizing (data) Copyright © Jeff Hart, 2015
  • 11. SpeakerRate.com • Search for “async” or “socalcodecamp” • h t t p : / / s p e a k e r r a t e . c o m / t a l k s / 4 9 3 2 1 - s o c a l c o d e c a m p - i n t r o - t o - a s y n c - a w a i t Thank YOU! Copyright © Jeff Hart, 2015 17