Joe Hummel, PhD Microsoft MVP Visual C++ Technical Staff: Pluralsight, LLC Professor: U. of Illinois, Chicago stuff:http://www.joehummel.net/downloads.html.

Slides:



Advertisements
Similar presentations
Microsoft Confidential. An incubation effort to: Support client -> server communication in native code with a modern C++ API design Support writing Azure-based.
Advertisements

Joe Hummel, PhD UC-Irvine
DEV324 C# VB 7.0 Managed Code C# VB 8.0 Generics C# VB 9.0 Language Integrated Query C# VB 10.0 Dynamic + Language Parity.
Pavel Yosifovich Hi-Tech College
Asynchronous programming Using Task, async and await Asynchronous programming1.
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!.
{ async patterns } - or - using the asynchronous library in the.Net 4.5 Framework for more than keeping your UI responsive.
Developing for Windows 8/WinRT Session 4 Fundamentals Kevin Stumpf.
please wait for the next slide clicking won’t make it come any faster.
Async Programming WITH ASYNC TASK
Windows 8 Metro / HTML5 JS “First Blood” Peter Kellner Microsoft MVP, ASP.NET ASPInsider Primary Organizer Silicon Valley Code.
Switching on the cloud for Silverlight MSDN Live Meeting Gill Cleeren Microsoft Regional Director – Silverlight MVP Ordina Belgium.
WHO WILL BENEFIT FROM THIS TALK TOPICS WHAT YOU’LL LEAVE WITH Web app developers who are already familiar with Windows Azure with scaling needs. Asynchronous.
Managed Code Generics Language Integrated Query Dynamic + Language Parity C# VB 11.0 Windows Runtime + Asynchrony C# VB 7.0 C# VB.
Joe Hummel, PhD Dept of Mathematics and Computer Science Lake Forest College Lecture 8: WebForms — Web-based.
App Windows UI object Windows object App code Windows object.
Lecture 8 – Platform as a Service. Introduction We have discussed the SPI model of Cloud Computing – IaaS – PaaS – SaaS.
Joe Hummel, PhD Dept of Mathematics and Computer Science Lake Forest College
Joe Hummel, PhD Visiting Researcher: U. of California, Irvine Adjunct Professor: U. of Illinois, Chicago & Loyola U., Chicago Materials:
Sofia, Bulgaria | 9-10 October Asynchronous Programming for ASP.NET 2.0 Developers Julie Lerman The Data Farm Julie Lerman The Data Farm.
Joe Hummel, PhD Technical Staff: Pluralsight Adjunct Professor: UIC, LUC
Silverlight 2 has rich networking support SOAP/XML Web services via WCF proxies Untyped HTTP services (REST, RSS, ATOM) via HttpWebRequest and WebClient.
Joe Hummel, PhD Visiting Researcher: U. of California, Irvine Adjunct Professor: U. of Illinois, Chicago & Loyola U., Chicago Materials:
Parallel Extensions A glimpse into the parallel universe By Eric De Carufel Microsoft.NET Solution Architect at Orckestra
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,
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Concurrency Patterns Emery Berger and Mark Corner University.
Joe Hummel, the compiler is at your service Chicago Code Camp 2014.
Future of VB and C# Lucian Wischik VB Language PM Microsoft.
WHO WILL BENEFIT FROM THIS TALK TOPICS WHAT YOU’LL LEAVE WITH ASP.NET developers, including Web Forms & MVC History of async programming in.NET How async.
Module 3: Using Microsoft.NET- Based Languages. Overview Overview of the.NET-Based Languages Comparison of the.NET-Based Languages.
Asynchronous Web Services Writing Asynchronous Web Services SoftUni Team Technical Trainers Software University
IAsyncResult ar = BeginSomething(…); // Do other work, checking ar.IsCompleted int result = EndSomething(ar);
Seminar Microsoft Next Generation Windows Services: By Microsoft. Guide Presented By Mr. Sandeep Gaikwad
Asynchronous Programming Writing Asynchronous Code in C# SoftUni Team Technical Trainers Software University
Joe Hummel, PhD Microsoft MVP Visual C++ Technical Staff: Pluralsight, LLC Professor: U. of Illinois, Chicago stuff:
Joe Hummel, the compiler is at your service SDC Meetup, Sept 2014.
TAP into async programming
Code Development for High Performance Servers Topics Multithreaded Servers Event Driven Servers Example - Game Server code (Quake) A parallelization exercise.
Patterns of Parallel Programming with.NET 4 Stephen Toub Principal Architect Parallel Computing Platform Microsoft Corporation
Nivo 300 ASP.NET MVC 4 Danijel Malik Artifis Danijel Malik s.p.
C# Present and Future Marita Paletsou Software Engineer.
C# 5.0 Alex Davies 22 nd December What we will cover C# 5.0,.NET 4.5, Visual Studio 11 Caller Info Attributes Upgrade from synchronous to asynchronous.
Joe Hummel, the compiler is at your service Chicago Coder Conference, June 2016.
//liveVirtualacademy2011/ What’s New for ASP.NET 4.5 and Web Development in Visual Studio 11 Developer Preview Γιώργος Καπνιάς MVP, MCT, MCDP, MCDBA, MCTS,
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
THE FUTURE OF C#: GOOD THINGS COME TO THOSE WHO ‘AWAIT’ Joseph Albahari SESSION CODE: DEV411 (c) 2011 Microsoft. All rights reserved.
Asynchronous Programming with C# v.Next
The Future of C# and Visual Basic
Web Concepts Lesson 2 ITBS2203 E-Commerce for IT.
TechEd /6/2018 6:15 AM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
Platform as a Service.
CS399 New Beginnings Jonathan Walpole.
Async or Parallel? No they aren’t the same thing!
Chapter 4: Multithreaded Programming
Staying Afloat in the .NET Async Ocean
12 Asynchronous Programming
Creating Windows Store Apps Using Visual Basic
Asynchronous Programming in .NET
Asynchronous Programming
Building responsive apps and sites with HTML5 web workers
F# for Parallel and Asynchronous Programming
Build /2/2019 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
CSE 451 Autumn 2003 Section 3 October 16.
Building Web Applications with Microsoft ASP
C# - Razor Pages Db/Scaffolding/Async
03 | Async Programming & Networking Intro
Threads CSE 2431: Introduction to Operating Systems
Presentation transcript:

Joe Hummel, PhD Microsoft MVP Visual C++ Technical Staff: Pluralsight, LLC Professor: U. of Illinois, Chicago stuff:

 To prevent blocking on long-running operations ◦ Client-side UI remains responsive vs. locking up ◦ Server-side scales vs. denying service 2

 Responsive UI… 3 void button1_Click(…) { var result = DoLongLatencyOp(); lstBox.Items.Add(result); } void button1_Click(…) { var result = DoLongLatencyOp(); lstBox.Items.Add(result); } async void button1_Click(…) { var result = await Task.Run(() => DoLongRunningOp()); lstBox.Items.Add(result); } async void button1_Click(…) { var result = await Task.Run(() => DoLongRunningOp()); lstBox.Items.Add(result); }

 Asian options financial modeling… 4

5 async void button1_Click(…) { var result = await Task.Run(() => DoLongRunningOp()); lstBox.Items.Add(result); } async void button1_Click(…) { var result = await Task.Run(() => DoLongRunningOp()); lstBox.Items.Add(result); } Method *may* perform async, long- latency op Tells compiler to setup a continuation that waits to execute rest of method on the current thread context. Meanwhile method can return while Task and continuation execute…

 await must wait on a task ◦ implies underlying method must create & start a task… 6 async void button1_Click(…) { var result = await Task.Run(() => DoLongRunningOp()); lstBox.Items.Add(result); } async void button1_Click(…) { var result = await Task.Run(() => DoLongRunningOp()); lstBox.Items.Add(result); } System.IO.FileStream file =...; int read = await file.ReadAsync(buffer, offset, count); System.IO.FileStream file =...; int read = await file.ReadAsync(buffer, offset, count);

 Think chunky, not chatty ◦ i.e. designed for coarse-grain, long-latency operations ◦ file I/O, network I/O, compute-bound work…  Async / await is *not* for ◦ Fire-and-forget (use a Task) ◦ High-performance parallelism (use Parallel.For) 7

 Use with APIs exposing “TAP” pattern ◦ Async / await take advantage of Task-based Asynchronous Pattern 8

 Scalable server-side… 9 string GetData(string url) { var client = new WebClient(); var page = client.DownloadString(url); return page; } string GetData(string url) { var client = new WebClient(); var page = client.DownloadString(url); return page; } async Task GetDataAsync(string url) { var client = new WebClient(); var page = await client.DownloadStringTaskAsync(url); return page; } async Task GetDataAsync(string url) { var client = new WebClient(); var page = await client.DownloadStringTaskAsync(url); return page; } "asynchrony" bubbles up to caller…

 Asynchronous web requests… 10

 Return a task for caller to await upon… 11 public int SomeOperation(...) { int result; result =...; return result; } public int SomeOperation(...) { int result; result =...; return result; } public Task SomeOperationAsync(...) { return Task.Run ( () => { int result; result =...; return result; } ); } public Task SomeOperationAsync(...) { return Task.Run ( () => { int result; result =...; return result; } ); }

12

 Use cases: ◦ Responsiveness: prevent blocking of the UI ◦ Scalability: prevent blocking of request-handling threads  Works with: ◦.NET on Windows server / desktop / tablet / phone ◦ Silverlight 4 and 5 ◦ ASP.NET server-side 13

 Presenter: Joe Hummel ◦ ◦ Materials:  For more info, see these issues of MSDN magazine: ◦ October 2011:series of intro articles ◦ March 2013:best practices ◦ October 2014:async / await on ASP.NET 14

 Programming model based on concept of a Task 15 Task == a unit of work; an object denoting an ongoing operation or computation.

16 void button1_Click(…) { var uictx = // grab UI thread context to run UI task: TaskScheduler.FromCurrentSynchronizationContext(); Task.Factory.StartNew(()=> { return DoLongLatencyOp(); } ).ContinueWith((antecedent) => { lstBox.Items.Add(antecedent.Result); }, uictx // execute this task on UI thread: ); } void button1_Click(…) { var uictx = // grab UI thread context to run UI task: TaskScheduler.FromCurrentSynchronizationContext(); Task.Factory.StartNew(()=> { return DoLongLatencyOp(); } ).ContinueWith((antecedent) => { lstBox.Items.Add(antecedent.Result); }, uictx // execute this task on UI thread: ); } void button1_Click(…) { var result = DoLongLatencyOp(); lstBox.Items.Add(result); } void button1_Click(…) { var result = DoLongLatencyOp(); lstBox.Items.Add(result); }

17 Windows Process (.NET) App Domain App Domain App Domain App Domain App Domain App Domain.NET Thread Pool worker thread worker thread worker thread worker thread Parallel.For(... ); task global work queue Task Parallel Library Resource Manager Task Scheduler Windows

18  Async programming:  Better responsiveness…  GUIs (desktop, web, mobile)  Cloud  Windows 8  Parallel programming:  Better performance…  Engineering  Oil and Gas  Pharma  Science  Social media Disk and network I/O number crunching and big data processing