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

Concurrency Important and difficult (Ada slides copied from Ed Schonberg)
CSCC69: Operating Systems
Click async Task LoadSettingsAsync() { await IO.Network.DownloadAsync(path); } async void Button1_Click(){ await LoadSettingsAsync(); UpdateView();
Asynchronous programming Using Task, async and await Asynchronous programming1.
Asynchronous Programming with C# and WinRT
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:
Chapter 11: Distributed Processing Parallel programming Principles of parallel programming languages Concurrent execution –Programming constructs –Guarded.
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.
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();
please wait for the next slide clicking won’t make it come any faster.
Chapter 6 - VB 2005 by Schneider1 Chapter 6 – Repetition 6.1 Do While and Do Until Loops 6.2 Processing Lists of Data with Do Loops 6.3 For...Next Loops.
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
Future of VB and C# Lucian Wischik VB Language PM Microsoft.
Internet Software Development Controlling Threads Paul J Krause.
Click async Task LoadSettingsAsync() { await IO.Network.DownloadAsync(path); } async void Button1_Click(){ await LoadSettingsAsync(); UpdateView();
Threaded Programming in Python Adapted from Fundamentals of Python: From First Programs Through Data Structures CPE 401 / 601 Computer Network Systems.
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
1 Client-Server Interaction. 2 Functionality Transport layer and layers below –Basic communication –Reliability Application layer –Abstractions Files.
Asynchronous Programming Writing Asynchronous Code in C# SoftUni Team Technical Trainers Software University
The Client-Server Model And the Socket API. Client-Server (1) The datagram service does not require cooperation between the peer applications but such.
Processes Creation and Threads. Shared Resource Example The console is just a place where text can be printed by the application currently running. Program.
Visual Basic. The Close Method The Close method is used to close a form. To close a form use the keyword Me to refer to the form. Me.Close()
CHAPTER 6 Threads, Handlers, and Programmatic Movement.
Computer Science Up Down Controls, Decisions and Random Numbers.
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
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#
Chapter 3 Process Management.
Chapter 6 Sub Procedures
12 Asynchronous Programming
Creating Windows Store Apps Using Visual Basic
CSE 154 Lecture 22: AJAX.
OverView of Scheduling
CS371m - Mobile Computing Responsiveness.
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
Building Web Applications with Microsoft ASP
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
More concurrency issues
Presentation transcript:

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

Click Sub LoadSettings() IO.File.ReadAllText(path) End Sub Sub Button1_Click(...) LoadSettings() UpdateView() End Sub Click Message pump

Click Sub LoadSettings() IO.Network.Download(path) End Sub Sub Button1_Click(...) LoadSettings() UpdateView() End Sub Click Message pump

Demo Add the Async & Await keywords

Async Sub Button1_Click(..) Await LoadSettingsAsync() UpdateView() End Sub Async Function LoadSettingsAsync() As Task Await IO.Network.DownloadAsync(path) End Sub Message pump Sub LoadSettings() IO.Network.Download(path) End Sub Sub Button1_Click(..) LoadSettings() UpdateView() End Sub Click

Async Function LoadSettingsAsync() As Task Await IO.Network.DownloadAsync(path) End Sub Async Sub Button1_Click(...) Await LoadSettingsAsync() UpdateView() End Sub 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 Function LoadSettingsAsync() As Task(Of Integer) Button1.IsEnabled = False Dim downTask = IO.Network.DownloadAsync(path) Me.Config = Await downTask Return Me.Config.Length End Function Async Sub Button1_Click() Dim loadTask = LoadSettingsAsync() Dim len = Await loadTask UpdateView() End Sub UI thread IOCP thread

Async Sub Button1_Click() Dim loadTask = LoadSettingsAsync() Dim len = Await loadTask UpdateView() End Sub Async Function LoadSettingsAsync() As Task(Of Integer) Button1.IsEnabled = False Dim downTask = IO.Network.DownloadAsync(path) Me.Config = Await downTask Return Me.Config.Length End Function UI thread IOCP thread Click [1/12] A button-click arrives on the UI queue

Async Sub Button1_Click() Dim loadTask = LoadSettingsAsync() Dim len = Await loadTask UpdateView() End Sub Async Function LoadSettingsAsync() As Task(Of Integer) Button1.IsEnabled = False Dim downTask = IO.Network.DownloadAsync(path) Me.Config = Await downTask Return Me.Config.Length End Function UI thread IOCP thread Click downTask [2/12] Invoke some functions; get back “downTask” from the API

Async Function LoadSettingsAsync() As Task(Of Integer) Button1.IsEnabled = False Dim downTask = IO.Network.DownloadAsync(path) Me.Config = Await downTask Return Me.Config.Length End Function downTask Async Sub Button1_Click() Dim loadTask = LoadSettingsAsync() Dim len = Await loadTask UpdateView() End Sub UI thread IOCP thread Click downTask » sc.Post{Κ1} [3/12] “Await downTask” assigns a continuation and returns loadTask loadTask Κ1:

Async Sub Button1_Click() Dim loadTask = LoadSettingsAsync() Dim len = Await loadTask UpdateView() End Sub loadTask Async Function LoadSettingsAsync() As Task(Of Integer) Button1.IsEnabled = False Dim downTask = IO.Network.DownloadAsync(path) Me.Config = Await downTask Return Me.Config.Length End Function 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 Sub Button1_Click() Dim loadTask = LoadSettingsAsync() Dim len = Await loadTask UpdateView() End Sub Async Function LoadSettingsAsync() As Task(Of Integer) Button1.IsEnabled = False Dim downTask = IO.Network.DownloadAsync(path) Me.Config = Await downTask Return Me.Config.Length End Function UI thread IOCP thread Click conf [5/12] Network packet arrives with data downTask » sc.Post{Κ1} Κ2: loadTask » sc.Post{Κ2} Κ1:

Async Sub Button1_Click() Dim loadTask = LoadSettingsAsync() Dim len = Await loadTask UpdateView() End Sub Async Function LoadSettingsAsync() As Task(Of Integer) Button1.IsEnabled = False Dim downTask = IO.Network.DownloadAsync(path) Me.Config = Await downTask Return Me.Config.Length End Function 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 Sub Button1_Click() Dim loadTask = LoadSettingsAsync() Dim len = Await loadTask UpdateView() End Sub Async Function LoadSettingsAsync() As Task(Of Integer) Button1.IsEnabled = False Dim downTask = IO.Network.DownloadAsync(path) Me.Config = Await downTask Return Me.Config.Length End Function 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 Sub Button1_Click() Dim loadTask = LoadSettingsAsync() Dim len = Await loadTask UpdateView() End Sub Async Function LoadSettingsAsync() As Task(Of Integer) Button1.IsEnabled = False Dim downTask = IO.Network.DownloadAsync(path) Me.Config = Await downTask Return Me.Config.Length End Function 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 Sub Button1_Click() Dim loadTask = LoadSettingsAsync() Dim len = Await loadTask UpdateView() End Sub Async Function LoadSettingsAsync() As Task(Of Integer) Button1.IsEnabled = False Dim downTask = IO.Network.DownloadAsync(path) Me.Config = Await downTask Return Me.Config.Length End Function 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 Sub Button1_Click() Dim loadTask = LoadSettingsAsync() Dim len = Await loadTask UpdateView() End Sub Async Function LoadSettingsAsync() As Task(Of Integer) Button1.IsEnabled = False Dim downTask = IO.Network.DownloadAsync(path) Me.Config = Await downTask Return Me.Config.Length End Function 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 Sub Button1_Click() Dim loadTask = LoadSettingsAsync() Dim len = Await loadTask UpdateView() End Sub Async Function LoadSettingsAsync() As Task(Of Integer) Button1.IsEnabled = False Dim downTask = IO.Network.DownloadAsync(path) Me.Config = Await downTask Return Me.Config.Length End Function 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 Function LoadSettingsAsync() As Task(Of Integer) Button1.IsEnabled = False Dim downTask = IO.Network.DownloadAsync(path) Me.Config = Await downTask Return Me.Config.Length End Function Async Sub Button1_Click() Dim loadTask = LoadSettingsAsync() Dim len = Await loadTask UpdateView() End Sub 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.”