SlideShare a Scribd company logo
1 of 32
C# 5 async & await Justin Lee Software Development Consultant Community Technology Update 2011 25th June 2011
Concurrency is… about running or appearing to run two things at once, through cooperative or pre-emptive multitasking or multicore. Good reasons to use concurrency: for the CPU-bound multicore computational kernel (e.g. codecs); for a server handling requests from different processes/machines; to “bet on more than one horse” and use whichever was fastest.
Asynchrony is… about results that are delayed, and yielding control while awaiting them (co-operative multitasking). Good reasons to use asynchrony: for overall control / coordination structure of a program; for UI responsiveness; for IO- and network-bound code; for coordinating your CPU-bound multicore computational kernel.
“A waiter’s job is to wait on a table until the patrons have finished their meal.If you want to serve two tables concurrently, you must hire two waiters.”
Demo Converting from synchronous, to asynchronous, to using await
UIthread IOCP thread asyncTask<string> LoadMoviesAsync() {var web = newWebClient(); vardTask = web.DownTaskAsync("http://netflix.com"); varrss = awaitdTask ; var movies = XElement.Parse(rss).<story>.<description>; return movies; } async voidSearchButtonClick() {vartask = QueryMoviesAsync(); varm = awaittask;    textBox1.Text = movies; } How the demo actually worked
UIthread [1/12] A button-click arrives on the UI queue IOCP thread async voidSearchButtonClick() {vartask = QueryMoviesAsync(); varm = awaittask;    textBox1.Text = movies; } asyncTask<string> LoadMoviesAsync() {var web = newWebClient(); vardTask = web.DownTaskAsync("http://netflix.com"); varrss = awaitdTask ; var movies = XElement.Parse(rss).<story>.<description>; return movies; } Click
UIthread [2/12] Invoke some functions; get back “dTask” from the API IOCP thread async voidSearchButtonClick() {vartask = QueryMoviesAsync(); varm = awaittask;    textBox1.Text = movies; } asyncTask<string> LoadMoviesAsync() {var web = newWebClient(); vardTask = web.DownTaskAsync("http://netflix.com"); varrss = awaitdTask ; var movies = XElement.Parse(rss).<story>.<description>; return movies; } Click dTask
UIthread [3/12] “await task” assigns a continuation and returns task IOCP thread asyncTask<string> LoadMoviesAsync() {var web = newWebClient(); var task = web.DownTaskAsync("http://netflix.com"); varrss = await task; var movies = XElement.Parse(rss).<story>.<description>; return movies; } async voidSearchButtonClick() {vartask = QueryMoviesAsync(); varm = awaittask;    textBox1.Text = movies; } Click task dTask dTask»ui.Post{Κ1} Κ1:
UIthread [4/12] “await task” assigns a continuation and returns IOCP thread async voidSearchButtonClick() {vartask = QueryMoviesAsync(); varm = awaittask;    textBox1.Text = movies; } asyncTask<string> LoadMoviesAsync() {var web = newWebClient(); vardTask = web.DownTaskAsync("http://netflix.com"); varrss = awaitdTask ; var movies = XElement.Parse(rss).<story>.<description>; return movies; } Click task task »ui.Post{Κ2} dTask»ui.Post{Κ1} Κ1: Κ2:
UIthread [5/12] Network packet arrives with data IOCP thread async voidSearchButtonClick() {vartask = QueryMoviesAsync(); varm = awaittask;    textBox1.Text = movies; } asyncTask<string> LoadMoviesAsync() {var web = newWebClient(); vardTask = web.DownTaskAsync("http://netflix.com"); varrss = awaitdTask ; var movies = XElement.Parse(rss).<story>.<description>; return movies; } Click task »ui.Post{Κ2} dTask»ui.Post{Κ1} rss Κ1: Κ2:
UIthread [6/12] Invoke dTask’scontinuation with that data IOCP thread async voidSearchButtonClick() {vartask = QueryMoviesAsync(); varm = awaittask;    textBox1.Text = movies; } asyncTask<string> LoadMoviesAsync() {var web = newWebClient(); vardTask = web.DownTaskAsync("http://netflix.com"); varrss = awaitdTask ; var movies = XElement.Parse(rss).<story>.<description>; return movies; } Click task »ui.Post{Κ2} dTask»ui.Post{Κ1} rss ui.Post{Κ1(rss)} Κ1: Κ2:
UIthread [7/12] Continuation is a “Post”, i.e. addition to the UI queue IOCP thread async voidSearchButtonClick() {vartask = QueryMoviesAsync(); varm = awaittask;    textBox1.Text = movies; } asyncTask<string> LoadMoviesAsync() {var web = newWebClient(); vardTask = web.DownTaskAsync("http://netflix.com"); varrss = awaitdTask ; var movies = XElement.Parse(rss).<story>.<description>; return movies; } Click task »ui.Post{Κ2} rss ui.Post{Κ1(rss)} Κ1: K1(rss) Κ2:
UIthread [8/12] UI thread executes K1, giving a result to the “await” IOCP thread async voidSearchButtonClick() {vartask = QueryMoviesAsync(); varm = awaittask;    textBox1.Text = movies; } asyncTask<string> LoadMoviesAsync() {var web = newWebClient(); vardTask = web.DownTaskAsync("http://netflix.com"); varrss = awaitdTask ; var movies = XElement.Parse(rss).<story>.<description>; return movies; } Click task »ui.Post{Κ2} rss ui.Post{Κ1(rss)} Κ1: K1(rss) Κ2:
UIthread [9/12] “return movies” will signal completion of task IOCP thread async voidSearchButtonClick() {vartask = QueryMoviesAsync(); varm = awaittask;    textBox1.Text = movies; } asyncTask<string> LoadMoviesAsync() {var web = newWebClient(); vardTask = web.DownTaskAsync("http://netflix.com"); varrss = awaitdTask ; var movies = XElement.Parse(rss).<story>.<description>; return movies; } Click task »ui.Post{Κ2} rss ui.Post{Κ1(rss)} Κ1: K1(rss) Κ2:
UIthread [10/12] Invoke task’s continuation with data  (by posting to UI queue) IOCP thread async voidSearchButtonClick() {vartask = QueryMoviesAsync(); varm = awaittask;    textBox1.Text = movies; } asyncTask<string> LoadMoviesAsync() {var web = newWebClient(); vardTask = web.DownTaskAsync("http://netflix.com"); varrss = awaitdTask ; var movies = XElement.Parse(rss).<story>.<description>; return movies; } Click task »ui.Post{Κ2} rss ui.Post{Κ1(rss)} Κ1: K1(rss) ui.Post(Κ2(movie)) Κ2: K2(movie)
UIthread [11/12] Return from handling the K1 continuation IOCP thread async voidSearchButtonClick() {vartask = QueryMoviesAsync(); varm = awaittask;    textBox1.Text = movies; } asyncTask<string> LoadMoviesAsync() {var web = newWebClient(); vardTask = web.DownTaskAsync("http://netflix.com"); varrss = awaitdTask ; var movies = XElement.Parse(rss).<story>.<description>; return movies; } Click rss ui.Post{Κ1(rss)} Κ1: K1(rss) ui.Post(Κ2(movie)) Κ2: K2(movie)
UIthread [12/12] UI thread executes K2, giving a result to the “await” IOCP thread async voidSearchButtonClick() {vartask = QueryMoviesAsync(); varm = awaittask;    textBox1.Text = movies; } asyncTask<string> LoadMoviesAsync() {var web = newWebClient(); vardTask = web.DownTaskAsync("http://netflix.com"); varrss = awaitdTask ; var movies = XElement.Parse(rss).<story>.<description>; return movies; } Click rss ui.Post{Κ1(rss)} Κ1: K1(rss) ui.Post(Κ2(movie)) Κ2: K2(movie)
Demo Using await and async with Silverlight
// network strings = awaitwebClient.DownloadStringTaskAsync("http://a.com"); strings = awaitwebClient.UploadStringTaskAsync(newUri("http://b"), "dat"); awaitWebRequest.Create("http://a.com").GetResponseAsync(); awaitsocket.ConnectAsync("a.com",80); awaitworkflowApplication.RunAsync(); awaitworkflowApplication.PersistAsync(); PingReply r = awaitping.SendTaskAsync("a.com"); // stream strings = awaittextReader.ReadToEndAsync(); awaitstream.WriteAsync(buffer, 0, 1024); awaitstream.CopyToAsync(stream2); // UI awaitpictureBox.LoadTaskAsync("http://a.com/pic.jpg"); awaitsoundPlayer.LoadTaskAsync(); // task/await, assuming “task” of type IEnumerable<Task<T>> T[] results = awaitTaskEx.WhenAll(tasks); Task<T>winner = awaitTaskEx.WhenAny(tasks); Task<T> task = TaskEx.Run(delegate {... return x;}); awaitTaskEx.Delay(100); awaitTaskEx.Yield(); awaitTaskScheduler.SwitchTo(); awaitDispatcher.SwitchTo(); Ultimately the contents of TaskEx will be moved into Task. How to use the “Task Async Pattern” [TAP]
classForm1 : Form { privatevoidbtnGo_Click(object sender, EventArgs e)     { cts = newCancellationTokenSource(); cts.CancelAfter(5000); try { awaitnewWebClient().DownloadStringTaskAsync(newUri("http://a.com"), cts.Token); awaitnewWebClient().DownloadStringTaskAsync(newUri("http://b.com"), cts.Token);        } catch (OperationCancelledException) { ... } finally {cts= null;}     } CancellationTokenSourcects; privatevoidbtnCancel_Click(object sender, EventArgs e)     { if (cts!=null) cts.Cancel(); } } This is the proposed new standard framework pattern for cancellation. Note that cancellation token is able to cancel the current operation in an async sequence; or it can cancel several concurrent async operations;  or you can take it as a parameter in your own async methods and pass it on to sub-methods. It is a “composable” way of doing cancellation. How to use TAP cancellation
classForm1 : Form { privatevoidbtnGo_Click(object sender, EventArgs e)     { varcts = newCancellationTokenSource(); cts.CancelAfter(5000); btnCancel.Click += cts.EventHandler; try { // a slicker, more local way to handle cancellation... awaitnewWebClient().DownloadStringTaskAsync(newUri("http://a.com"), cts.Token); awaitnewWebClient().DownloadStringTaskAsync(newUri("http://b.com"), cts.Token); } catch (OperationCancelledException) { ... } finally{btnCancel.Click -= cts.EventHandler;} } } publicstaticclassExtensions {   publicstaticvoidEventHandler(thisCancellationTokenSourcects, object_, EventArgs e) {  cts.Cancel();  } } In this version, we keep “cts” local to just the operation it controls. Note that “cts” can’t be re-used: once it has been cancelled, it remains cancelled. That’s why we create a new one each time the user clicks “Go”. A good idea: btnGo.Enabled=false; btnCancel.Enabled=true; How to use TAP cancellation [advanced]
privatevoid btnGo_Click(object sender, EventArgs e) { var progress = newEventProgress<DownloadProgressChangedEventArgs>(); // Set up a progress-event-handler (which will always fire on the UI thread, // even if we'd launched the task ona different thread).     progress.ProgressChanged += (_, ee) =>     {         progressBar1.Value = ee.Value.ProgressPercentage;     }; // Wait for the task to finish awaitnewWebClient().DownloadStringTaskAsync(uri, cts.Token, progress); } interfaceIProgress<T> {   voidReport(T value); } This is the proposed new standard framework pattern for progress-reporting (for those APIs that support progress-reporting). ,[object Object]
This parameter is EventProgress<T>, or any other class that implements IProgress<T>... (it’s up to the consumer how to deal with progress)How to use TAP progress
// handle progress with a "while" loop, instead of a callback: varprogress = newLatestProgress<DownloadProgressChangedEventArgs>(); vartask = newWebClient().DownloadStringTaskAsync(uri, cts.Token, progress); while(await progress.Progress(task)) {     progressBar1.Value = progress.Latest.ProgressPercentage; } // another “while” loop, except this one queues up reports so we don’t lose any: varprogress = newQueuedProgress<DownloadProgressChangedEventArgs>(); vartask = newWebClient().DownloadStringTaskAsync(uri, cts.Token, progress); while(await progress.NextProgress(task)) { progressBar1.Value = progress.Current.ProgressPercentage; } ,[object Object]
PULL techniques are ones where UI thread choses when it wants to pull the next report – e.g. LatestProgress, QueuedProgress.
The classes LatestProgresss and QueuedProgress are in the “ProgressAndCancellation” sample in the CTP.How to use TAP progress [advanced]
Task<string[]> GetAllAsync(Uri[] uris, CancellationTokencancel, IProgress<int> progress) { var results = newstring[uris.Length]; for (int i=0; i<uris.Length; i++) {         cancel.ThrowIfCancellationRequested(); results[i] = awaitnewWebClient().DownloadStringTaskAsync(uris[i], cancel); if (progress!=null) progress.Report(i); } return results; } Take Cancel/progress parameters: If your API supports both cancellation and progress, add a single overload which takes both. If it supports just one, add a single overload which takes it. Listen for cancellation: either do the pull technique of “cancel.ThrowIfCancellationRequested()” in your inner loop, or the push technique of “cancel.Register(Action)” to be notified of cancellation, or... Pass cancellation down: usually it will be appropriate to pass the cancellation down to nested async functions that you call. Report progress: in your inner loop, as often as makes sense, report progress. The argument to progress.Report(i) may be read from a different thread, so make sure it’s either read-only or threadsafe. How to implement TAP cancellation/progress
Task                  Delay(intms, CancellationTokencancel); Task<T>               Run<T>(Func<T> function); Task<IEnumerable<T>>  WhenAll<T>(IEnumerable<Task<T>> tasks); Task<Task<T>> WhenAny<T>(IEnumerable<Task<T>> tasks); // WhenAny is like Select. When you await it, you get the task that “won”. // WhenAll over a LINQ query int[] results = awaitTaskEx.WhenAll(fromurlinurlsselectGetIntAsync(url)); // WhenAny to implement a concurrent worker pool Queue<string> todo= ...; var workers = newHashSet<Task<int>>(); for(inti=0; i<10; i++) workers.Add(GetIntAsync(todo.Dequeue()); while (workers.Count>0) { var winner = awaitTaskEx.WhenAny(workers); Console.WriteLine(await winner); workers.Remove(winner); if (todo.Count>0) workers.Add(GetIntAsync(todo.Dequeue()); } Task<T> combinators
asyncvoidFireAndForgetAsync() { await t; } asyncTask MerelySignalCompletionAsync() { return; } AsyncTask<int> GiveResultAsync() { return 15; } FireAndForgetAsync(); awaitMerelySignalCompletionAsync(); varr = awaitGiveResultAsync(); Async subs (“void-returning asyncs”): used for “fire-and-forget” scenarios. Control will return to the caller after the first Await. But once “t” has finished, the continuation will be posted to the current synchronization context. Any exceptions will be thrown on that context. Task-returning asyncs: Used if you merely want to know when the task has finished. Exceptions get squirrelled away inside the resultant Task. Task(Of T)-returning asyncs: Used if you want to know the result as well. Three kinds of asyncmethod
 // Task Asynchronous Pattern [TAP], with Cancellation and Progress Task<TR> GetStringAsync(Params..., [CancellationTokenCancel],                                   [IProgress<TP>Progress])  // Asynchronous Programming Model [APM]IAsyncResultBeginGetString(Params..., AsyncCallbackCallback, object state);TR EndGetString(IAsyncResult);     // Event-based Asynchronous Pattern [EAP]classC { publicvoidGetStringAsync(Params...); publiceventGetStringCompletedEventHandlerGetStringCompleted;     publicvoidCancelAsync(); } classGetStringCompletedEventArgs {     publicTR Result { get; } publicException Error { get; } } Comparing TAP to its predecessors
Demo Progress and Cancellation

More Related Content

What's hot

Asynchronous programming in .net 4.5 with c#
Asynchronous programming in .net 4.5 with c#Asynchronous programming in .net 4.5 with c#
Asynchronous programming in .net 4.5 with c#Binu Bhasuran
 
Asynchronous Programming in C# - Part 1
Asynchronous Programming in C# - Part 1Asynchronous Programming in C# - Part 1
Asynchronous Programming in C# - Part 1Mindfire Solutions
 
Asynchronous Programming in ASP.NET
Asynchronous Programming in ASP.NETAsynchronous Programming in ASP.NET
Asynchronous Programming in ASP.NETChris Dufour
 
Task parallel library presentation
Task parallel library presentationTask parallel library presentation
Task parallel library presentationahmed sayed
 
Async Await for Mobile Apps
Async Await for Mobile AppsAsync Await for Mobile Apps
Async Await for Mobile AppsCraig Dunn
 
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 SafarXamarin
 
Intro to Functional Programming with RxJava
Intro to Functional Programming with RxJavaIntro to Functional Programming with RxJava
Intro to Functional Programming with RxJavaMike Nakhimovich
 
Reactive programming with Rxjava
Reactive programming with RxjavaReactive programming with Rxjava
Reactive programming with RxjavaChristophe Marchal
 
Developer-friendly taskqueues: What you should ask yourself before choosing one
Developer-friendly taskqueues: What you should ask yourself before choosing oneDeveloper-friendly taskqueues: What you should ask yourself before choosing one
Developer-friendly taskqueues: What you should ask yourself before choosing oneSylvain Zimmer
 
Reactive Programming with Rx
 Reactive Programming with Rx Reactive Programming with Rx
Reactive Programming with RxC4Media
 
Async/Await: TPL & Message Pumps
Async/Await: TPL & Message Pumps Async/Await: TPL & Message Pumps
Async/Await: TPL & Message Pumps Particular Software
 
Gude for C++11 in Apache Traffic Server
Gude for C++11 in Apache Traffic ServerGude for C++11 in Apache Traffic Server
Gude for C++11 in Apache Traffic ServerApache Traffic Server
 
Asynchronous job queues with python-rq
Asynchronous job queues with python-rqAsynchronous job queues with python-rq
Asynchronous job queues with python-rqAshish Acharya
 
Salesforce DUG - Queueable Apex
Salesforce DUG - Queueable ApexSalesforce DUG - Queueable Apex
Salesforce DUG - Queueable ApexAkshay Varu
 
Streams, Streams Everywhere! An Introduction to Rx
Streams, Streams Everywhere! An Introduction to RxStreams, Streams Everywhere! An Introduction to Rx
Streams, Streams Everywhere! An Introduction to RxAndrzej Sitek
 
Gatling @ Scala.Io 2013
Gatling @ Scala.Io 2013Gatling @ Scala.Io 2013
Gatling @ Scala.Io 2013slandelle
 
Using Grails to power your electric car
Using Grails to power your electric carUsing Grails to power your electric car
Using Grails to power your electric carMarco Pas
 

What's hot (20)

Asynchronous programming in .net 4.5 with c#
Asynchronous programming in .net 4.5 with c#Asynchronous programming in .net 4.5 with c#
Asynchronous programming in .net 4.5 with c#
 
Asynchronous Programming in C# - Part 1
Asynchronous Programming in C# - Part 1Asynchronous Programming in C# - Part 1
Asynchronous Programming in C# - Part 1
 
Asynchronous Programming in ASP.NET
Asynchronous Programming in ASP.NETAsynchronous Programming in ASP.NET
Asynchronous Programming in ASP.NET
 
Task parallel library presentation
Task parallel library presentationTask parallel library presentation
Task parallel library presentation
 
Async Await for Mobile Apps
Async Await for Mobile AppsAsync Await for Mobile Apps
Async Await for Mobile Apps
 
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
 
Async await...oh wait!
Async await...oh wait!Async await...oh wait!
Async await...oh wait!
 
Intro to Functional Programming with RxJava
Intro to Functional Programming with RxJavaIntro to Functional Programming with RxJava
Intro to Functional Programming with RxJava
 
Reactive programming with Rxjava
Reactive programming with RxjavaReactive programming with Rxjava
Reactive programming with Rxjava
 
Developer-friendly taskqueues: What you should ask yourself before choosing one
Developer-friendly taskqueues: What you should ask yourself before choosing oneDeveloper-friendly taskqueues: What you should ask yourself before choosing one
Developer-friendly taskqueues: What you should ask yourself before choosing one
 
AMC Minor Technical Issues
AMC Minor Technical IssuesAMC Minor Technical Issues
AMC Minor Technical Issues
 
Reactive Programming with Rx
 Reactive Programming with Rx Reactive Programming with Rx
Reactive Programming with Rx
 
Async/Await: TPL & Message Pumps
Async/Await: TPL & Message Pumps Async/Await: TPL & Message Pumps
Async/Await: TPL & Message Pumps
 
Gude for C++11 in Apache Traffic Server
Gude for C++11 in Apache Traffic ServerGude for C++11 in Apache Traffic Server
Gude for C++11 in Apache Traffic Server
 
Asynchronous job queues with python-rq
Asynchronous job queues with python-rqAsynchronous job queues with python-rq
Asynchronous job queues with python-rq
 
Async/Await Best Practices
Async/Await Best PracticesAsync/Await Best Practices
Async/Await Best Practices
 
Salesforce DUG - Queueable Apex
Salesforce DUG - Queueable ApexSalesforce DUG - Queueable Apex
Salesforce DUG - Queueable Apex
 
Streams, Streams Everywhere! An Introduction to Rx
Streams, Streams Everywhere! An Introduction to RxStreams, Streams Everywhere! An Introduction to Rx
Streams, Streams Everywhere! An Introduction to Rx
 
Gatling @ Scala.Io 2013
Gatling @ Scala.Io 2013Gatling @ Scala.Io 2013
Gatling @ Scala.Io 2013
 
Using Grails to power your electric car
Using Grails to power your electric carUsing Grails to power your electric car
Using Grails to power your electric car
 

Viewers also liked

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 MelbourneFilip Ekberg
 
Evolution of C# delegates
Evolution of C# delegatesEvolution of C# delegates
Evolution of C# delegatesmbaric
 
Modos de transmisión
Modos de transmisión Modos de transmisión
Modos de transmisión la católica
 
Async await in C++
Async await in C++Async await in C++
Async await in C++cppfrug
 
C#을 이용한 task 병렬화와 비동기 패턴
C#을 이용한 task 병렬화와 비동기 패턴C#을 이용한 task 병렬화와 비동기 패턴
C#을 이용한 task 병렬화와 비동기 패턴명신 김
 
C# Delegates and Event Handling
C# Delegates and Event HandlingC# Delegates and Event Handling
C# Delegates and Event HandlingJussi Pohjolainen
 
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)Eduard Tomàs
 

Viewers also liked (8)

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
 
Modos de transmisión
Modos de transmisión Modos de transmisión
Modos de transmisión
 
Async await in C++
Async await in C++Async await in C++
Async await in C++
 
C#을 이용한 task 병렬화와 비동기 패턴
C#을 이용한 task 병렬화와 비동기 패턴C#을 이용한 task 병렬화와 비동기 패턴
C#을 이용한 task 병렬화와 비동기 패턴
 
C# Delegates and Event Handling
C# Delegates and Event HandlingC# Delegates and Event Handling
C# Delegates and Event Handling
 
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)
 
C# Delegates
C# DelegatesC# Delegates
C# Delegates
 

Similar to CTU June 2011 - C# 5.0 - ASYNC & Await

Non Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJavaNon Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJavaFrank Lyaruu
 
Server side JavaScript: going all the way
Server side JavaScript: going all the wayServer side JavaScript: going all the way
Server side JavaScript: going all the wayOleg Podsechin
 
Ordina SOFTC Presentation - Async CTP
Ordina SOFTC Presentation - Async CTPOrdina SOFTC Presentation - Async CTP
Ordina SOFTC Presentation - Async CTPOrdina Belgium
 
Parallel Processing
Parallel ProcessingParallel Processing
Parallel ProcessingRTigger
 
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade ServerlessKatyShimizu
 
[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade ServerlessKatyShimizu
 
Behind modern concurrency primitives
Behind modern concurrency primitivesBehind modern concurrency primitives
Behind modern concurrency primitivesBartosz Sypytkowski
 
GDG Jakarta Meetup - Streaming Analytics With Apache Beam
GDG Jakarta Meetup - Streaming Analytics With Apache BeamGDG Jakarta Meetup - Streaming Analytics With Apache Beam
GDG Jakarta Meetup - Streaming Analytics With Apache BeamImre Nagi
 
Deep Dive async/await in Unity with UniTask(EN)
Deep Dive async/await in Unity with UniTask(EN)Deep Dive async/await in Unity with UniTask(EN)
Deep Dive async/await in Unity with UniTask(EN)Yoshifumi Kawai
 
Kotlin from-scratch 3 - coroutines
Kotlin from-scratch 3 - coroutinesKotlin from-scratch 3 - coroutines
Kotlin from-scratch 3 - coroutinesFranco Lombardo
 
4Developers 2018: Real-time capabilities in ASP.NET Core web applications (To...
4Developers 2018: Real-time capabilities in ASP.NET Core web applications (To...4Developers 2018: Real-time capabilities in ASP.NET Core web applications (To...
4Developers 2018: Real-time capabilities in ASP.NET Core web applications (To...PROIDEA
 
Behind modern concurrency primitives
Behind modern concurrency primitivesBehind modern concurrency primitives
Behind modern concurrency primitivesBartosz Sypytkowski
 
No Callbacks, No Threads - RailsConf 2010
No Callbacks, No Threads - RailsConf 2010No Callbacks, No Threads - RailsConf 2010
No Callbacks, No Threads - RailsConf 2010Ilya Grigorik
 
Structured concurrency with Kotlin Coroutines
Structured concurrency with Kotlin CoroutinesStructured concurrency with Kotlin Coroutines
Structured concurrency with Kotlin CoroutinesVadims Savjolovs
 
Introduction to Vert.x
Introduction to Vert.xIntroduction to Vert.x
Introduction to Vert.xYiguang Hu
 
Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaYevgeniy Brikman
 
Anton Moldovan "Load testing which you always wanted"
Anton Moldovan "Load testing which you always wanted"Anton Moldovan "Load testing which you always wanted"
Anton Moldovan "Load testing which you always wanted"Fwdays
 
Stackless Python In Eve
Stackless Python In EveStackless Python In Eve
Stackless Python In Evel xf
 
Stackless Python In Eve
Stackless Python In EveStackless Python In Eve
Stackless Python In Eveguest91855c
 

Similar to CTU June 2011 - C# 5.0 - ASYNC & Await (20)

Non Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJavaNon Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJava
 
JS everywhere 2011
JS everywhere 2011JS everywhere 2011
JS everywhere 2011
 
Server side JavaScript: going all the way
Server side JavaScript: going all the wayServer side JavaScript: going all the way
Server side JavaScript: going all the way
 
Ordina SOFTC Presentation - Async CTP
Ordina SOFTC Presentation - Async CTPOrdina SOFTC Presentation - Async CTP
Ordina SOFTC Presentation - Async CTP
 
Parallel Processing
Parallel ProcessingParallel Processing
Parallel Processing
 
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
 
[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless
 
Behind modern concurrency primitives
Behind modern concurrency primitivesBehind modern concurrency primitives
Behind modern concurrency primitives
 
GDG Jakarta Meetup - Streaming Analytics With Apache Beam
GDG Jakarta Meetup - Streaming Analytics With Apache BeamGDG Jakarta Meetup - Streaming Analytics With Apache Beam
GDG Jakarta Meetup - Streaming Analytics With Apache Beam
 
Deep Dive async/await in Unity with UniTask(EN)
Deep Dive async/await in Unity with UniTask(EN)Deep Dive async/await in Unity with UniTask(EN)
Deep Dive async/await in Unity with UniTask(EN)
 
Kotlin from-scratch 3 - coroutines
Kotlin from-scratch 3 - coroutinesKotlin from-scratch 3 - coroutines
Kotlin from-scratch 3 - coroutines
 
4Developers 2018: Real-time capabilities in ASP.NET Core web applications (To...
4Developers 2018: Real-time capabilities in ASP.NET Core web applications (To...4Developers 2018: Real-time capabilities in ASP.NET Core web applications (To...
4Developers 2018: Real-time capabilities in ASP.NET Core web applications (To...
 
Behind modern concurrency primitives
Behind modern concurrency primitivesBehind modern concurrency primitives
Behind modern concurrency primitives
 
No Callbacks, No Threads - RailsConf 2010
No Callbacks, No Threads - RailsConf 2010No Callbacks, No Threads - RailsConf 2010
No Callbacks, No Threads - RailsConf 2010
 
Structured concurrency with Kotlin Coroutines
Structured concurrency with Kotlin CoroutinesStructured concurrency with Kotlin Coroutines
Structured concurrency with Kotlin Coroutines
 
Introduction to Vert.x
Introduction to Vert.xIntroduction to Vert.x
Introduction to Vert.x
 
Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and Scala
 
Anton Moldovan "Load testing which you always wanted"
Anton Moldovan "Load testing which you always wanted"Anton Moldovan "Load testing which you always wanted"
Anton Moldovan "Load testing which you always wanted"
 
Stackless Python In Eve
Stackless Python In EveStackless Python In Eve
Stackless Python In Eve
 
Stackless Python In Eve
Stackless Python In EveStackless Python In Eve
Stackless Python In Eve
 

More from Spiffy

01 server manager spiffy
01 server manager spiffy01 server manager spiffy
01 server manager spiffySpiffy
 
Active Directory Upgrade
Active Directory UpgradeActive Directory Upgrade
Active Directory UpgradeSpiffy
 
Checking the health of your active directory enviornment
Checking the health of your active directory enviornmentChecking the health of your active directory enviornment
Checking the health of your active directory enviornmentSpiffy
 
Agile in Action - Act 2: Development
Agile in Action - Act 2: DevelopmentAgile in Action - Act 2: Development
Agile in Action - Act 2: DevelopmentSpiffy
 
Agile in Action - Act 3: Testing
Agile in Action - Act 3: TestingAgile in Action - Act 3: Testing
Agile in Action - Act 3: TestingSpiffy
 
Agile in Action - Keynote: Becoming and Being Agile - What Does This Mean?
Agile in Action - Keynote: Becoming and Being Agile - What Does This Mean?Agile in Action - Keynote: Becoming and Being Agile - What Does This Mean?
Agile in Action - Keynote: Becoming and Being Agile - What Does This Mean?Spiffy
 
Agile in Action - Act 1 (Set Up, Planning, Requirements and Architecture)
Agile in Action - Act 1 (Set Up, Planning, Requirements and Architecture)Agile in Action - Act 1 (Set Up, Planning, Requirements and Architecture)
Agile in Action - Act 1 (Set Up, Planning, Requirements and Architecture)Spiffy
 
MS TechDays 2011 - WCF Web APis There's a URI for That
MS TechDays 2011 - WCF Web APis There's a URI for ThatMS TechDays 2011 - WCF Web APis There's a URI for That
MS TechDays 2011 - WCF Web APis There's a URI for ThatSpiffy
 
MS TechDays 2011 - NUI, Gooey and Louie
MS TechDays 2011 - NUI, Gooey and LouieMS TechDays 2011 - NUI, Gooey and Louie
MS TechDays 2011 - NUI, Gooey and LouieSpiffy
 
MS TechDays 2011 - Mango, Mango! Developing for Windows Phone 7
MS TechDays 2011 - Mango, Mango! Developing for Windows Phone 7MS TechDays 2011 - Mango, Mango! Developing for Windows Phone 7
MS TechDays 2011 - Mango, Mango! Developing for Windows Phone 7Spiffy
 
MS TechDays 2011 - Generate Revenue on Azure
MS TechDays 2011 - Generate Revenue on AzureMS TechDays 2011 - Generate Revenue on Azure
MS TechDays 2011 - Generate Revenue on AzureSpiffy
 
MS TechDays 2011 - HTML 5 All the Awesome Bits
MS TechDays 2011 - HTML 5 All the Awesome BitsMS TechDays 2011 - HTML 5 All the Awesome Bits
MS TechDays 2011 - HTML 5 All the Awesome BitsSpiffy
 
MS TechDays 2011 - Cloud Computing with the Windows Azure Platform
MS TechDays 2011 - Cloud Computing with the Windows Azure PlatformMS TechDays 2011 - Cloud Computing with the Windows Azure Platform
MS TechDays 2011 - Cloud Computing with the Windows Azure PlatformSpiffy
 
MS TechDays 2011 - Simplified Converged Infrastructure Solutions
MS TechDays 2011 - Simplified Converged Infrastructure SolutionsMS TechDays 2011 - Simplified Converged Infrastructure Solutions
MS TechDays 2011 - Simplified Converged Infrastructure SolutionsSpiffy
 
MS TechDays 2011 - SCDPM 2012 The New Feature of Data Protection
MS TechDays 2011 - SCDPM 2012 The New Feature of Data ProtectionMS TechDays 2011 - SCDPM 2012 The New Feature of Data Protection
MS TechDays 2011 - SCDPM 2012 The New Feature of Data ProtectionSpiffy
 
MS TechDays 2011 - Microsoft Exchange Server and Office 365 Hybrid Deployment
MS TechDays 2011 - Microsoft Exchange Server and Office 365 Hybrid DeploymentMS TechDays 2011 - Microsoft Exchange Server and Office 365 Hybrid Deployment
MS TechDays 2011 - Microsoft Exchange Server and Office 365 Hybrid DeploymentSpiffy
 
MS TechDays 2011 - How to Run Middleware in the Cloud Story of Windows Azure ...
MS TechDays 2011 - How to Run Middleware in the Cloud Story of Windows Azure ...MS TechDays 2011 - How to Run Middleware in the Cloud Story of Windows Azure ...
MS TechDays 2011 - How to Run Middleware in the Cloud Story of Windows Azure ...Spiffy
 
MS TechDays 2011 - Cloud Management with System Center Application Controller
MS TechDays 2011 - Cloud Management with System Center Application ControllerMS TechDays 2011 - Cloud Management with System Center Application Controller
MS TechDays 2011 - Cloud Management with System Center Application ControllerSpiffy
 
MS TechDays 2011 - Virtualization Solutions to Optimize Performance
MS TechDays 2011 - Virtualization Solutions to Optimize PerformanceMS TechDays 2011 - Virtualization Solutions to Optimize Performance
MS TechDays 2011 - Virtualization Solutions to Optimize PerformanceSpiffy
 
MS TechDays 2011 - Automating Your Infrastructure System Center Orchestrator ...
MS TechDays 2011 - Automating Your Infrastructure System Center Orchestrator ...MS TechDays 2011 - Automating Your Infrastructure System Center Orchestrator ...
MS TechDays 2011 - Automating Your Infrastructure System Center Orchestrator ...Spiffy
 

More from Spiffy (20)

01 server manager spiffy
01 server manager spiffy01 server manager spiffy
01 server manager spiffy
 
Active Directory Upgrade
Active Directory UpgradeActive Directory Upgrade
Active Directory Upgrade
 
Checking the health of your active directory enviornment
Checking the health of your active directory enviornmentChecking the health of your active directory enviornment
Checking the health of your active directory enviornment
 
Agile in Action - Act 2: Development
Agile in Action - Act 2: DevelopmentAgile in Action - Act 2: Development
Agile in Action - Act 2: Development
 
Agile in Action - Act 3: Testing
Agile in Action - Act 3: TestingAgile in Action - Act 3: Testing
Agile in Action - Act 3: Testing
 
Agile in Action - Keynote: Becoming and Being Agile - What Does This Mean?
Agile in Action - Keynote: Becoming and Being Agile - What Does This Mean?Agile in Action - Keynote: Becoming and Being Agile - What Does This Mean?
Agile in Action - Keynote: Becoming and Being Agile - What Does This Mean?
 
Agile in Action - Act 1 (Set Up, Planning, Requirements and Architecture)
Agile in Action - Act 1 (Set Up, Planning, Requirements and Architecture)Agile in Action - Act 1 (Set Up, Planning, Requirements and Architecture)
Agile in Action - Act 1 (Set Up, Planning, Requirements and Architecture)
 
MS TechDays 2011 - WCF Web APis There's a URI for That
MS TechDays 2011 - WCF Web APis There's a URI for ThatMS TechDays 2011 - WCF Web APis There's a URI for That
MS TechDays 2011 - WCF Web APis There's a URI for That
 
MS TechDays 2011 - NUI, Gooey and Louie
MS TechDays 2011 - NUI, Gooey and LouieMS TechDays 2011 - NUI, Gooey and Louie
MS TechDays 2011 - NUI, Gooey and Louie
 
MS TechDays 2011 - Mango, Mango! Developing for Windows Phone 7
MS TechDays 2011 - Mango, Mango! Developing for Windows Phone 7MS TechDays 2011 - Mango, Mango! Developing for Windows Phone 7
MS TechDays 2011 - Mango, Mango! Developing for Windows Phone 7
 
MS TechDays 2011 - Generate Revenue on Azure
MS TechDays 2011 - Generate Revenue on AzureMS TechDays 2011 - Generate Revenue on Azure
MS TechDays 2011 - Generate Revenue on Azure
 
MS TechDays 2011 - HTML 5 All the Awesome Bits
MS TechDays 2011 - HTML 5 All the Awesome BitsMS TechDays 2011 - HTML 5 All the Awesome Bits
MS TechDays 2011 - HTML 5 All the Awesome Bits
 
MS TechDays 2011 - Cloud Computing with the Windows Azure Platform
MS TechDays 2011 - Cloud Computing with the Windows Azure PlatformMS TechDays 2011 - Cloud Computing with the Windows Azure Platform
MS TechDays 2011 - Cloud Computing with the Windows Azure Platform
 
MS TechDays 2011 - Simplified Converged Infrastructure Solutions
MS TechDays 2011 - Simplified Converged Infrastructure SolutionsMS TechDays 2011 - Simplified Converged Infrastructure Solutions
MS TechDays 2011 - Simplified Converged Infrastructure Solutions
 
MS TechDays 2011 - SCDPM 2012 The New Feature of Data Protection
MS TechDays 2011 - SCDPM 2012 The New Feature of Data ProtectionMS TechDays 2011 - SCDPM 2012 The New Feature of Data Protection
MS TechDays 2011 - SCDPM 2012 The New Feature of Data Protection
 
MS TechDays 2011 - Microsoft Exchange Server and Office 365 Hybrid Deployment
MS TechDays 2011 - Microsoft Exchange Server and Office 365 Hybrid DeploymentMS TechDays 2011 - Microsoft Exchange Server and Office 365 Hybrid Deployment
MS TechDays 2011 - Microsoft Exchange Server and Office 365 Hybrid Deployment
 
MS TechDays 2011 - How to Run Middleware in the Cloud Story of Windows Azure ...
MS TechDays 2011 - How to Run Middleware in the Cloud Story of Windows Azure ...MS TechDays 2011 - How to Run Middleware in the Cloud Story of Windows Azure ...
MS TechDays 2011 - How to Run Middleware in the Cloud Story of Windows Azure ...
 
MS TechDays 2011 - Cloud Management with System Center Application Controller
MS TechDays 2011 - Cloud Management with System Center Application ControllerMS TechDays 2011 - Cloud Management with System Center Application Controller
MS TechDays 2011 - Cloud Management with System Center Application Controller
 
MS TechDays 2011 - Virtualization Solutions to Optimize Performance
MS TechDays 2011 - Virtualization Solutions to Optimize PerformanceMS TechDays 2011 - Virtualization Solutions to Optimize Performance
MS TechDays 2011 - Virtualization Solutions to Optimize Performance
 
MS TechDays 2011 - Automating Your Infrastructure System Center Orchestrator ...
MS TechDays 2011 - Automating Your Infrastructure System Center Orchestrator ...MS TechDays 2011 - Automating Your Infrastructure System Center Orchestrator ...
MS TechDays 2011 - Automating Your Infrastructure System Center Orchestrator ...
 

Recently uploaded

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 

Recently uploaded (20)

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 

CTU June 2011 - C# 5.0 - ASYNC & Await

  • 1. C# 5 async & await Justin Lee Software Development Consultant Community Technology Update 2011 25th June 2011
  • 2. Concurrency is… about running or appearing to run two things at once, through cooperative or pre-emptive multitasking or multicore. Good reasons to use concurrency: for the CPU-bound multicore computational kernel (e.g. codecs); for a server handling requests from different processes/machines; to “bet on more than one horse” and use whichever was fastest.
  • 3. Asynchrony is… about results that are delayed, and yielding control while awaiting them (co-operative multitasking). Good reasons to use asynchrony: for overall control / coordination structure of a program; for UI responsiveness; for IO- and network-bound code; for coordinating your CPU-bound multicore computational kernel.
  • 4. “A waiter’s job is to wait on a table until the patrons have finished their meal.If you want to serve two tables concurrently, you must hire two waiters.”
  • 5. Demo Converting from synchronous, to asynchronous, to using await
  • 6. UIthread IOCP thread asyncTask<string> LoadMoviesAsync() {var web = newWebClient(); vardTask = web.DownTaskAsync("http://netflix.com"); varrss = awaitdTask ; var movies = XElement.Parse(rss).<story>.<description>; return movies; } async voidSearchButtonClick() {vartask = QueryMoviesAsync(); varm = awaittask; textBox1.Text = movies; } How the demo actually worked
  • 7. UIthread [1/12] A button-click arrives on the UI queue IOCP thread async voidSearchButtonClick() {vartask = QueryMoviesAsync(); varm = awaittask; textBox1.Text = movies; } asyncTask<string> LoadMoviesAsync() {var web = newWebClient(); vardTask = web.DownTaskAsync("http://netflix.com"); varrss = awaitdTask ; var movies = XElement.Parse(rss).<story>.<description>; return movies; } Click
  • 8. UIthread [2/12] Invoke some functions; get back “dTask” from the API IOCP thread async voidSearchButtonClick() {vartask = QueryMoviesAsync(); varm = awaittask; textBox1.Text = movies; } asyncTask<string> LoadMoviesAsync() {var web = newWebClient(); vardTask = web.DownTaskAsync("http://netflix.com"); varrss = awaitdTask ; var movies = XElement.Parse(rss).<story>.<description>; return movies; } Click dTask
  • 9. UIthread [3/12] “await task” assigns a continuation and returns task IOCP thread asyncTask<string> LoadMoviesAsync() {var web = newWebClient(); var task = web.DownTaskAsync("http://netflix.com"); varrss = await task; var movies = XElement.Parse(rss).<story>.<description>; return movies; } async voidSearchButtonClick() {vartask = QueryMoviesAsync(); varm = awaittask; textBox1.Text = movies; } Click task dTask dTask»ui.Post{Κ1} Κ1:
  • 10. UIthread [4/12] “await task” assigns a continuation and returns IOCP thread async voidSearchButtonClick() {vartask = QueryMoviesAsync(); varm = awaittask; textBox1.Text = movies; } asyncTask<string> LoadMoviesAsync() {var web = newWebClient(); vardTask = web.DownTaskAsync("http://netflix.com"); varrss = awaitdTask ; var movies = XElement.Parse(rss).<story>.<description>; return movies; } Click task task »ui.Post{Κ2} dTask»ui.Post{Κ1} Κ1: Κ2:
  • 11. UIthread [5/12] Network packet arrives with data IOCP thread async voidSearchButtonClick() {vartask = QueryMoviesAsync(); varm = awaittask; textBox1.Text = movies; } asyncTask<string> LoadMoviesAsync() {var web = newWebClient(); vardTask = web.DownTaskAsync("http://netflix.com"); varrss = awaitdTask ; var movies = XElement.Parse(rss).<story>.<description>; return movies; } Click task »ui.Post{Κ2} dTask»ui.Post{Κ1} rss Κ1: Κ2:
  • 12. UIthread [6/12] Invoke dTask’scontinuation with that data IOCP thread async voidSearchButtonClick() {vartask = QueryMoviesAsync(); varm = awaittask; textBox1.Text = movies; } asyncTask<string> LoadMoviesAsync() {var web = newWebClient(); vardTask = web.DownTaskAsync("http://netflix.com"); varrss = awaitdTask ; var movies = XElement.Parse(rss).<story>.<description>; return movies; } Click task »ui.Post{Κ2} dTask»ui.Post{Κ1} rss ui.Post{Κ1(rss)} Κ1: Κ2:
  • 13. UIthread [7/12] Continuation is a “Post”, i.e. addition to the UI queue IOCP thread async voidSearchButtonClick() {vartask = QueryMoviesAsync(); varm = awaittask; textBox1.Text = movies; } asyncTask<string> LoadMoviesAsync() {var web = newWebClient(); vardTask = web.DownTaskAsync("http://netflix.com"); varrss = awaitdTask ; var movies = XElement.Parse(rss).<story>.<description>; return movies; } Click task »ui.Post{Κ2} rss ui.Post{Κ1(rss)} Κ1: K1(rss) Κ2:
  • 14. UIthread [8/12] UI thread executes K1, giving a result to the “await” IOCP thread async voidSearchButtonClick() {vartask = QueryMoviesAsync(); varm = awaittask; textBox1.Text = movies; } asyncTask<string> LoadMoviesAsync() {var web = newWebClient(); vardTask = web.DownTaskAsync("http://netflix.com"); varrss = awaitdTask ; var movies = XElement.Parse(rss).<story>.<description>; return movies; } Click task »ui.Post{Κ2} rss ui.Post{Κ1(rss)} Κ1: K1(rss) Κ2:
  • 15. UIthread [9/12] “return movies” will signal completion of task IOCP thread async voidSearchButtonClick() {vartask = QueryMoviesAsync(); varm = awaittask; textBox1.Text = movies; } asyncTask<string> LoadMoviesAsync() {var web = newWebClient(); vardTask = web.DownTaskAsync("http://netflix.com"); varrss = awaitdTask ; var movies = XElement.Parse(rss).<story>.<description>; return movies; } Click task »ui.Post{Κ2} rss ui.Post{Κ1(rss)} Κ1: K1(rss) Κ2:
  • 16. UIthread [10/12] Invoke task’s continuation with data (by posting to UI queue) IOCP thread async voidSearchButtonClick() {vartask = QueryMoviesAsync(); varm = awaittask; textBox1.Text = movies; } asyncTask<string> LoadMoviesAsync() {var web = newWebClient(); vardTask = web.DownTaskAsync("http://netflix.com"); varrss = awaitdTask ; var movies = XElement.Parse(rss).<story>.<description>; return movies; } Click task »ui.Post{Κ2} rss ui.Post{Κ1(rss)} Κ1: K1(rss) ui.Post(Κ2(movie)) Κ2: K2(movie)
  • 17. UIthread [11/12] Return from handling the K1 continuation IOCP thread async voidSearchButtonClick() {vartask = QueryMoviesAsync(); varm = awaittask; textBox1.Text = movies; } asyncTask<string> LoadMoviesAsync() {var web = newWebClient(); vardTask = web.DownTaskAsync("http://netflix.com"); varrss = awaitdTask ; var movies = XElement.Parse(rss).<story>.<description>; return movies; } Click rss ui.Post{Κ1(rss)} Κ1: K1(rss) ui.Post(Κ2(movie)) Κ2: K2(movie)
  • 18. UIthread [12/12] UI thread executes K2, giving a result to the “await” IOCP thread async voidSearchButtonClick() {vartask = QueryMoviesAsync(); varm = awaittask; textBox1.Text = movies; } asyncTask<string> LoadMoviesAsync() {var web = newWebClient(); vardTask = web.DownTaskAsync("http://netflix.com"); varrss = awaitdTask ; var movies = XElement.Parse(rss).<story>.<description>; return movies; } Click rss ui.Post{Κ1(rss)} Κ1: K1(rss) ui.Post(Κ2(movie)) Κ2: K2(movie)
  • 19. Demo Using await and async with Silverlight
  • 20. // network strings = awaitwebClient.DownloadStringTaskAsync("http://a.com"); strings = awaitwebClient.UploadStringTaskAsync(newUri("http://b"), "dat"); awaitWebRequest.Create("http://a.com").GetResponseAsync(); awaitsocket.ConnectAsync("a.com",80); awaitworkflowApplication.RunAsync(); awaitworkflowApplication.PersistAsync(); PingReply r = awaitping.SendTaskAsync("a.com"); // stream strings = awaittextReader.ReadToEndAsync(); awaitstream.WriteAsync(buffer, 0, 1024); awaitstream.CopyToAsync(stream2); // UI awaitpictureBox.LoadTaskAsync("http://a.com/pic.jpg"); awaitsoundPlayer.LoadTaskAsync(); // task/await, assuming “task” of type IEnumerable<Task<T>> T[] results = awaitTaskEx.WhenAll(tasks); Task<T>winner = awaitTaskEx.WhenAny(tasks); Task<T> task = TaskEx.Run(delegate {... return x;}); awaitTaskEx.Delay(100); awaitTaskEx.Yield(); awaitTaskScheduler.SwitchTo(); awaitDispatcher.SwitchTo(); Ultimately the contents of TaskEx will be moved into Task. How to use the “Task Async Pattern” [TAP]
  • 21. classForm1 : Form { privatevoidbtnGo_Click(object sender, EventArgs e) { cts = newCancellationTokenSource(); cts.CancelAfter(5000); try { awaitnewWebClient().DownloadStringTaskAsync(newUri("http://a.com"), cts.Token); awaitnewWebClient().DownloadStringTaskAsync(newUri("http://b.com"), cts.Token); } catch (OperationCancelledException) { ... } finally {cts= null;} } CancellationTokenSourcects; privatevoidbtnCancel_Click(object sender, EventArgs e) { if (cts!=null) cts.Cancel(); } } This is the proposed new standard framework pattern for cancellation. Note that cancellation token is able to cancel the current operation in an async sequence; or it can cancel several concurrent async operations; or you can take it as a parameter in your own async methods and pass it on to sub-methods. It is a “composable” way of doing cancellation. How to use TAP cancellation
  • 22. classForm1 : Form { privatevoidbtnGo_Click(object sender, EventArgs e) { varcts = newCancellationTokenSource(); cts.CancelAfter(5000); btnCancel.Click += cts.EventHandler; try { // a slicker, more local way to handle cancellation... awaitnewWebClient().DownloadStringTaskAsync(newUri("http://a.com"), cts.Token); awaitnewWebClient().DownloadStringTaskAsync(newUri("http://b.com"), cts.Token); } catch (OperationCancelledException) { ... } finally{btnCancel.Click -= cts.EventHandler;} } } publicstaticclassExtensions { publicstaticvoidEventHandler(thisCancellationTokenSourcects, object_, EventArgs e) { cts.Cancel(); } } In this version, we keep “cts” local to just the operation it controls. Note that “cts” can’t be re-used: once it has been cancelled, it remains cancelled. That’s why we create a new one each time the user clicks “Go”. A good idea: btnGo.Enabled=false; btnCancel.Enabled=true; How to use TAP cancellation [advanced]
  • 23.
  • 24. This parameter is EventProgress<T>, or any other class that implements IProgress<T>... (it’s up to the consumer how to deal with progress)How to use TAP progress
  • 25.
  • 26. PULL techniques are ones where UI thread choses when it wants to pull the next report – e.g. LatestProgress, QueuedProgress.
  • 27. The classes LatestProgresss and QueuedProgress are in the “ProgressAndCancellation” sample in the CTP.How to use TAP progress [advanced]
  • 28. Task<string[]> GetAllAsync(Uri[] uris, CancellationTokencancel, IProgress<int> progress) { var results = newstring[uris.Length]; for (int i=0; i<uris.Length; i++) { cancel.ThrowIfCancellationRequested(); results[i] = awaitnewWebClient().DownloadStringTaskAsync(uris[i], cancel); if (progress!=null) progress.Report(i); } return results; } Take Cancel/progress parameters: If your API supports both cancellation and progress, add a single overload which takes both. If it supports just one, add a single overload which takes it. Listen for cancellation: either do the pull technique of “cancel.ThrowIfCancellationRequested()” in your inner loop, or the push technique of “cancel.Register(Action)” to be notified of cancellation, or... Pass cancellation down: usually it will be appropriate to pass the cancellation down to nested async functions that you call. Report progress: in your inner loop, as often as makes sense, report progress. The argument to progress.Report(i) may be read from a different thread, so make sure it’s either read-only or threadsafe. How to implement TAP cancellation/progress
  • 29. Task Delay(intms, CancellationTokencancel); Task<T> Run<T>(Func<T> function); Task<IEnumerable<T>> WhenAll<T>(IEnumerable<Task<T>> tasks); Task<Task<T>> WhenAny<T>(IEnumerable<Task<T>> tasks); // WhenAny is like Select. When you await it, you get the task that “won”. // WhenAll over a LINQ query int[] results = awaitTaskEx.WhenAll(fromurlinurlsselectGetIntAsync(url)); // WhenAny to implement a concurrent worker pool Queue<string> todo= ...; var workers = newHashSet<Task<int>>(); for(inti=0; i<10; i++) workers.Add(GetIntAsync(todo.Dequeue()); while (workers.Count>0) { var winner = awaitTaskEx.WhenAny(workers); Console.WriteLine(await winner); workers.Remove(winner); if (todo.Count>0) workers.Add(GetIntAsync(todo.Dequeue()); } Task<T> combinators
  • 30. asyncvoidFireAndForgetAsync() { await t; } asyncTask MerelySignalCompletionAsync() { return; } AsyncTask<int> GiveResultAsync() { return 15; } FireAndForgetAsync(); awaitMerelySignalCompletionAsync(); varr = awaitGiveResultAsync(); Async subs (“void-returning asyncs”): used for “fire-and-forget” scenarios. Control will return to the caller after the first Await. But once “t” has finished, the continuation will be posted to the current synchronization context. Any exceptions will be thrown on that context. Task-returning asyncs: Used if you merely want to know when the task has finished. Exceptions get squirrelled away inside the resultant Task. Task(Of T)-returning asyncs: Used if you want to know the result as well. Three kinds of asyncmethod
  • 31.  // Task Asynchronous Pattern [TAP], with Cancellation and Progress Task<TR> GetStringAsync(Params..., [CancellationTokenCancel], [IProgress<TP>Progress])  // Asynchronous Programming Model [APM]IAsyncResultBeginGetString(Params..., AsyncCallbackCallback, object state);TR EndGetString(IAsyncResult);  // Event-based Asynchronous Pattern [EAP]classC { publicvoidGetStringAsync(Params...); publiceventGetStringCompletedEventHandlerGetStringCompleted; publicvoidCancelAsync(); } classGetStringCompletedEventArgs { publicTR Result { get; } publicException Error { get; } } Comparing TAP to its predecessors
  • 32. Demo Progress and Cancellation
  • 33. Demo Async on Windows Phone 7 (if there’s time)
  • 34. Q & A triplez@justinlee.sg

Editor's Notes

  1. * Let&apos;s talk about this with waiters.* Read slowly: &quot;A waiters job...&quot;* Flaw in this. Can you see what it is? Obviously, a waiter can interleave!
  2. [Joke: oh, you don’t want to go home early? Great. In that case I’ll dive into how it actually worked under the hood.]GOALS: To understand the “await” feature at a professional level -- that is, where the flow-of-control goes, which threads are involved, and how they communicate. Also to understand more deeply what asynchrony is. This will be enable you to be a better architect of asynchronous programs, e.g. Silverlight and ASP.This is the demo code, but I simplified it a little. I also split up “GetDiggAsync” and “await” onto separate lines. (Also I ported it over mostly to C#, apart from the XML literals).There are two existing threads allocated by the operating system. One is the UI thread for this process. The other is the “IO Completion Port” thread. Each of these threads has a queue associated with it.
  3. When the user clicks a button, this inserts a “button-click-message” into the UI queue.The UI thread is in a while loop, checking for messages. When it gets this message it invokes the button-click handler.
  4. The same thread makes function calls.When it calls the API “web.DownloadStringTaskAsync”, this returns immediately. It returns a Task, which I’ve called “downTask”. This task has not yet completed. The network stack will know to mark it as completed once the server’s response comes back.I should stress that “Task” does not mean a “BackgroundThreadTask”. The Task class is unrelated to questions of threads of execution.A “Task” is merely a “future” (C++), a “promise” – it’s an object that exists in one of three states, “InProgress” or “Completed(with result)” or “Faulted(with exception)”. It can be caused to transition from the first state to either of the other two. When this transition takes place, it will invoke any continuations that have been registered with it.And Task is a great unifying abstraction. That’s because it can stand for so many things – for a background worker thread on the current machine, or for a thread of execution on some remote database server, or for things that don’t take any threads at all like a button-click or a DMA transfer from disk to memory.Actually, if you’re familiar with the TPL, Task has a third state “Cancelled”. Through APIs we end up treating this state as equivalent to Faulted(with OperationCancelledException).
  5. Now we execute the “await” operator. This does two things.First, it signs up a continuation onto downTask. For now I’ve written the continuation as “ui.Post{K1}” – not in real syntax. We’ll see later what it does. (Note that a task is allowed to have many continuations signed up on it.)Next, the first time we execute the “await” operator in an async method, we return a Task immediately. Once again, this task has not yet completed.
  6. We execute the “await” operator. once again, this signs up a continuation onto the task, and returns to the calling thread (the UI thread).The UI thread can now resume it’s “while”-loop, checking for messages.If any other button-clicks happened (or mouse-drags or repaints or window-resizing) now, then they could be dealt with by the UI thread fine. This is where responsiveness comes in. (but it also brings in re-entrancy... imagine if the user clicked the same button again! then we’d start a second concurrent run through this button1_Click handler!)
  7. Hey! A few seconds later, and the web services has delivered its answer to the IO Completion Port thread!
  8. The IOCP thread knows which task was associated with that response.So it transitions it from the “Running” state to the “Completed with result ‘rss’” state. This causes it to execute the task’s continuation.
  9. The continuation merely adds a message into the UI queue. Then it returns, allowing the IO Completion Port thread to resume its work.
  10. The UI thread picks up the message from its queue, and responds by dispatching to K1, which assigns into the variable “rss”.
  11. The code continues to execute. it comes to the “return” statement.(note that we have already returned the Task&lt;string&gt; “diggTask” from this method. So you know the return statement is going to do something different...)
  12. The “return” statement, in an async method, sets its returned task’s state to “Completed”, provides a result, and executes the task’s continuation.Once again, the continuation merely posts to the UI’s message-queue.
  13. The method returns. Now the UI-thread can go back to its “while” loop, checking for messages in the queue. (There is one already!)
  14. And the UI thread executes the method, puts the story into the text-box, and finishes.Note that ALL user code executed on the UI thread. All of it. That means the user never had to worry about the typical multi-threaded problems (semaphores, mutexes, semaphores, races, locks, ...)Also count how many threads were involved. Just the two that were already provided by the operating system. We didn’t create ANY additional threads.
  15. These are some of the “Task Async Pattern” APIs that are included in the CTP.
  16. We initially hadvar task2 = task.TimeoutAfter(1000);But we removed it because it didn’t have a clear-enough design. Would you want task2 to end with an OperationCancelledException after 1000ms? Or to end successfully? Both forms are useful. In the end, we figured that cancellation-after-1000ms was easier done like this:varcts = new CancellationTokenSource();cts.CancelAfter(1000)And we figured that successful-termination-after-1000ms was clearer if you wrote it out manually:var task2 = task.WhenAny(task, Task.Delay(1000))
  17. There are three kinds of async methods. The difference between them is subtle.The difference between them is so subtle that we considered eliminating the first kind “void-returning asyncs” entirely. But that would have been wrong. That’s because every single async method you write will be invoked by someone who is also async, all the way up to the very top level of the callstack, to the “fire-and-forget” event handlers at the top like Button1_Click().So: every program that you’ll ever write will use void-returning asyncs. We have to accept that, and include it as a language feature.
  18. Something to note here is that Task is composable.For instance, you can write a method which takes any two tasks and awaits until they’re both done.You can’t do that with the APM or the EAP. That’s because APM is just “a pair of methods with arbitrary parameters” and WebClient is just “a set of methods and events you have to call”. They’re not first-class citizens. They’re not things that you can pass as parameters to another method. But you can pass a Task directly to another method.That’s why the TAP is better.