please wait for the next slide clicking won’t make it come any faster.

Slides:



Advertisements
Similar presentations
TechReady 16 4/1/2017 Async Clinic
Advertisements

Section 3. True/False Changing the order of semaphores’ operations in a program does not matter. False.
Concurrency Important and difficult (Ada slides copied from Ed Schonberg)
CSCC69: Operating Systems
Multithreaded Programs in Java. Tasks and Threads A task is an abstraction of a series of steps – Might be done in a separate thread – Java libraries.
Click async Task LoadSettingsAsync() { await IO.Network.DownloadAsync(path); } async void Button1_Click(){ await LoadSettingsAsync(); UpdateView();
Asynchronous Programming with C# and WinRT
Joe Hummel, PhD Microsoft MVP Visual C++ Technical Staff: Pluralsight, LLC Adjunct Professor: U. of Illinois, Chicago and Loyola University Chicago
Asynchronous programming Deadlock All The Things!.
Developing for Windows 8/WinRT Session 4 Fundamentals Kevin Stumpf.
please wait for the next slide clicking won’t make it come any faster.
Principles Async void is a “fire-and-forget” mechanism… The caller is unable to know when an async void has finished The caller is unable.
Lucian Wischik VB+C# language PM Microsoft Corporation The Future of VB and C#
Async Programming WITH ASYNC TASK
Multithreading The objectives of this chapter are:
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Async void is only for top-level event handlers. Use TaskCompletionSource to wrap Tasks around events. Use the threadpool for CPU-bound code, but not.
Apps are notified when they have been resumed.
App Windows UI object Windows object App code Windows object.
Joe Hummel, PhD Technical Staff: Pluralsight Adjunct Professor: UIC, LUC
Click async Task LoadSettingsAsync() { await IO.Network.DownloadAsync(path); } async void Button1_Click(){ await LoadSettingsAsync(); UpdateView();
Consuming REST Services from C# SoftUni Team Technical Trainers Software University
Parallel Programming: Responsiveness vs. Performance Joe Hummel, PhD Microsoft MVP Visual C++ Technical Staff: Pluralsight, LLC Professor: U. of Illinois,
SIMPLE PARALLEL PROGRAMMING WITH PATTERNS AND OMNITHREADLIBRARY PRIMOŽ GABRIJELČIČ SKYPE: GABR42
Joe Hummel, PhD Microsoft MVP Visual C++ Technical Staff: Pluralsight, LLC Professor: U. of Illinois, Chicago stuff:
Future of VB and C# Lucian Wischik VB Language PM Microsoft.
Internet Software Development Controlling Threads Paul J Krause.
Working in the Background Radan Ganchev Astea Solutions.
Click async Task LoadSettingsAsync() { await IO.Network.DownloadAsync(path); } async void Button1_Click(){ await LoadSettingsAsync(); UpdateView();
CS378 - Mobile Computing Responsiveness. An App Idea From Nifty Assignments Draw a picture use randomness Pick an equation at random Operators in the.
Introduction MySQL won't actually execute the query, just analyse it EXPLAIN helps us understand how and when MySQL will use indexes EXPLAIN returns a.
Asynchronous Web Services Writing Asynchronous Web Services SoftUni Team Technical Trainers Software University
In Java processes are called threads. Additional threads are associated with objects. An application is associated with an initial thread via a static.
S -1 Posix Threads. S -2 Thread Concepts Threads are "lightweight processes" –10 to 100 times faster than fork() Threads share: –process instructions,
Asynchronous Programming Writing Asynchronous Code in C# SoftUni Team Technical Trainers Software University
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 More on Thread API.
Processes Creation and Threads. Shared Resource Example The console is just a place where text can be printed by the application currently running. Program.
TAP into async programming
please wait for the next slide clicking won’t make it come any faster.
Async Made Simple in Windows 8, with C# and Visual Basic Alex Turner Program Manager VB/C# Compilers Microsoft Corporation DEV332.
Asynchronous Programming Writing Concurrent Code in C# SoftUni Team Technical Trainers Software University
Concepts of Multithreading CS 378 – Mobile Computing for iOS Dr. William C. Bulko.
Multithreading The objectives of this chapter are:
Concurrency in Android
Multithreading / Concurrency
Asynchronous Programming with C# v.Next
The Future of C# and Visual Basic
Lab11 – MobileUIFrontEnd-BluemixBackend
TechEd /6/2018 6:15 AM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
Using Microsoft Visual Basic to Build Windows Phone Applications
Async or Parallel? No they aren’t the same thing!
Reactive Android Development
Cert Exam Prep: Exam : Programming with C#
12 Asynchronous Programming
Creating Windows Store Apps Using Visual Basic
CSE 154 Lecture 22: AJAX.
OverView of Scheduling
Android Topics UI Thread and Limited processing resources
Build /2/2019 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
Android Topics Asynchronous Callsbacks
Android Topics Threads and the MessageQueue
Hold up, wait a minute, let me put some async in it
Threads in Java James Brucker.
User Segmentation and Targeted Push Notifications for UWP apps
EECE.4810/EECE.5730 Operating Systems
Multithreading The objectives of this chapter are:
Software Engineering and Architecture
03 | Async Programming & Networking Intro
Chapter 3: Process Management
Android Threads Dimitar Ivanov Mobile Applications with Android
Presentation transcript:

please wait for the next slide clicking won’t make it come any faster

Click void LoadSettings() { IO.File.ReadAllText(path); } void Button1_Click() { LoadSettings(); UpdateView(); } Click Message pump

Click void LoadSettings() { IO.Network.Download(path); } void Button1_Click() { LoadSettings(); UpdateView(); } Click Message pump

Demo Add the Async & Await keywords

async Task LoadSettingsAsync() { await IO.Network.DownloadAsync(path); } void LoadSettings() { IO.Network.Download(path); } async void Button1_Click() { await LoadSettingsAsync(); UpdateView(); } void Button1_Click(..) { LoadSettings(); UpdateView(); } Message pump Click

async Task LoadSettingsAsync() { await IO.Network.DownloadAsync(path); } async void Button1_Click(){ await LoadSettingsAsync(); UpdateView(); } Click Message pump Task... DownloadAsync Task... LoadSettingsAsync Download LoadSettings

Demo Async UI app: re-entrancy and deadlock Async unit test Async console app

Photo: Rüdiger Wölk

Demo Using the Task type for compositional algorithms Cancellation

This is the IL that’s emitted when you use async/await

Async Task LoadSettingsAsync() { Button1.IsEnabled = False; var downTask = IO.Network.DownloadAsync(path); this.Config = await downTask; return this.Config.Length; } async void Button1_Click() { var loadTask = LoadSettingsAsync(); var len = await loadTask; UpdateView(); } UI thread IOCP thread

async void Button1_Click() { var loadTask = LoadSettingsAsync(); var len = await loadTask; UpdateView(); } Async Task LoadSettingsAsync() { Button1.IsEnabled = False; var downTask = IO.Network.DownloadAsync(path); this.Config = await downTask; return this.Config.Length; } UI thread IOCP thread Click [1/12] A button-click arrives on the UI queue

async void Button1_Click() { var loadTask = LoadSettingsAsync(); var len = await loadTask; UpdateView(); } Async Task LoadSettingsAsync() { Button1.IsEnabled = False; var downTask = IO.Network.DownloadAsync(path); this.Config = await downTask; return this.Config.Length; } UI thread IOCP thread Click downTask [2/12] Invoke some functions; get back “downTask” from the API

Async Task LoadSettingsAsync() { Button1.IsEnabled = False; var downTask = IO.Network.DownloadAsync(path); this.Config = await downTask; return this.Config.Length; } downTask async void Button1_Click() { var loadTask = LoadSettingsAsync(); var len = await loadTask; UpdateView(); } UI thread IOCP thread Click downTask » sc.Post{Κ1} [3/12] “Await downTask” assigns a continuation and returns loadTask loadTask Κ1:

async void Button1_Click() { var loadTask = LoadSettingsAsync(); var len = await loadTask; UpdateView(); } loadTask Async Task LoadSettingsAsync() { Button1.IsEnabled = False; var downTask = IO.Network.DownloadAsync(path); this.Config = await downTask; return this.Config.Length; } UI thread IOCP thread Click downTask » sc.Post{Κ1} [4/12] “Await loadTask” assigns a continuation and returns Κ2: loadTask » sc.Post{Κ2} Κ1:

async void Button1_Click() { var loadTask = LoadSettingsAsync(); var len = await loadTask; UpdateView(); } Async Task LoadSettingsAsync() { Button1.IsEnabled = False; var downTask = IO.Network.DownloadAsync(path); this.Config = await downTask; return this.Config.Length; } UI thread IOCP thread Click conf [5/12] Network packet arrives with data downTask » sc.Post{Κ1} Κ2: loadTask » sc.Post{Κ2} Κ1:

async void Button1_Click() { var loadTask = LoadSettingsAsync(); var len = await loadTask; UpdateView(); } Async Task LoadSettingsAsync() { Button1.IsEnabled = False; var downTask = IO.Network.DownloadAsync(path); this.Config = await downTask; return this.Config.Length; } UI thread IOCP thread Click conf sc.Post{Κ1(conf)} [6/12] Invoke downTask’s continuation with that data downTask » sc.Post{Κ1} Κ2: loadTask » sc.Post{Κ2} Κ1:

async void Button1_Click() { var loadTask = LoadSettingsAsync(); var len = await loadTask; UpdateView(); } Async Task LoadSettingsAsync() { Button1.IsEnabled = False; var downTask = IO.Network.DownloadAsync(path); this.Config = await downTask; return this.Config.Length; } UI thread IOCP thread Click loadTask » sc.Post{Κ2} conf K1(conf) [7/12] Continuation is a “Post”, i.e. addition to the UI queue Κ2: sc.Post{Κ1(conf)} Κ1:

async void Button1_Click() { var loadTask = LoadSettingsAsync(); var len = await loadTask; UpdateView(); } Async Task LoadSettingsAsync() { Button1.IsEnabled = False; var downTask = IO.Network.DownloadAsync(path); this.Config = await downTask; return this.Config.Length; } UI thread IOCP thread Click conf K1(conf) [8/12] UI thread executes K1 Κ2: sc.Post{Κ1(conf)} loadTask » sc.Post{Κ2} Κ1:

async void Button1_Click() { var loadTask = LoadSettingsAsync(); var len = await loadTask; UpdateView(); } Async Task LoadSettingsAsync() { Button1.IsEnabled = False; var downTask = IO.Network.DownloadAsync(path); this.Config = await downTask; return this.Config.Length; } UI thread IOCP thread Click conf K1(conf) [9/12] Return statement will signal completion of loadTask Κ2: sc.Post{Κ1(conf)} loadTask » sc.Post{Κ2} Κ1:

async void Button1_Click() { var loadTask = LoadSettingsAsync(); var len = await loadTask; UpdateView(); } Async Task LoadSettingsAsync() { Button1.IsEnabled = False; var downTask = IO.Network.DownloadAsync(path); this.Config = await downTask; return this.Config.Length; } UI thread IOCP thread Click conf K1(conf) sc.Post(Κ2(len)) [10/12] Invoke loadTask’s continuation with data (by posting to UI queue) K2(len) Κ2: sc.Post{Κ1(rss)} loadTask » sc.Post{Κ2} Κ1:

async void Button1_Click() { var loadTask = LoadSettingsAsync(); var len = await loadTask; UpdateView(); } Async Task LoadSettingsAsync() { Button1.IsEnabled = False; var downTask = IO.Network.DownloadAsync(path); this.Config = await downTask; return this.Config.Length; } UI thread IOCP thread Click conf K1(rss) sc.Post(Κ2(len)) K2(len) [11/12] Return from handling the K1 continuation Κ2: sc.Post{Κ1(conf)} Κ1:

Async Task LoadSettingsAsync() { Button1.IsEnabled = False; var downTask = IO.Network.DownloadAsync(path); this.Config = await downTask; return this.Config.Length; } async void Button1_Click() { var loadTask = LoadSettingsAsync(); var len = await loadTask; UpdateView(); } conf K2(len) Click K1(rss) UI thread IOCP thread sc.Post(Κ2(len)) Κ1: Κ2: [12/12] UI thread executes K2 sc.Post{Κ1(conf)}

“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.”

The following is from the Android dev blog. Can you spot the flaw? 1. “A good practice in creating responsive applications is to make sure your main UI thread does the minimum amount of work.” 2. “Any potentially long task that may hang your application should be handled in a different thread.” 3. “Typical examples of such tasks are network operations, which involve unpredictable delays.”