THE FUTURE OF C#: GOOD THINGS COME TO THOSE WHO ‘AWAIT’ Joseph Albahari SESSION CODE: DEV411 (c) 2011 Microsoft. All rights reserved.

Slides:



Advertisements
Similar presentations
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Advertisements

© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Feature: Identity Management - Login © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
FUTURE OF.NET PARALLEL PROGRAMMING Joseph Albahari SESSION CODE: DEV308 (c) 2011 Microsoft. All rights reserved.
Feature: Reprint Outstanding Transactions Report © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product.
MVC - LESSONS LEARNT FROM BEING BURNT Malcolm Sheridan - Quantitative Project Leader ANZ SESSION CODE: #WEB306.
Feature: Purchase Requisitions - Requester © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
MIX 09 4/15/ :14 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Windows 7 Training Microsoft Confidential. Windows ® 7 Compatibility Version Checking.
Multitenant Model Request/Response General Model.
Feature: Purchase Order Prepayments II © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
Announcing Demo Announcing.
Feature: OLE Notes Migration Utility
NEW WINDOWS PHONE “MANGO” APPLICATION PLATFORM SERVICES Chris blog.walshie.me SESSION CODE: WPH304 (c) 2011 Microsoft. All rights.
Feature: Web Client Keyboard Shortcuts © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
Feature: SmartList Usability Enhancements © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
Session 1.
Built by Developers for Developers…. © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Feature: Assign an Item to Multiple Sites © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Feature: Print Remaining Documents © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
Connect with life Connect with life
NEXT: Overview – Sharing skills & code.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Feature: Document Attachment –Replace OLE Notes © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product.
Feature: Customer Combiner and Modifier © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
Please visit m.ausalgo.com on your device and sign inm.ausalgo.com.
demo Instance AInstance B Read “7” Write “8”

customer.
CONNECTING PHONE APPLICATIONS TO THE CLOUD Nick Randolph (Built to Roam) SESSION CODE: COS-WPH208 (c) 2011 Microsoft. All rights reserved.
INTRODUCTION TO WINDOWS AZURE APPFABRIC COMPOSITE APPLICATIONS Lewis Benge Creative Technologist Whybin\TBWA\Tequila SESSION CODE: COS-MID306.
CROSS PLATFORM MOBILE APPLICATION DEVELOPMENT Nick Randolph (Built to Roam) SESSION CODE: DEV-WPH314 (c) 2011 Microsoft. All rights reserved.
demo © 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
demo Demo.
Feature: Void Historical/Open Transaction Updates © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product.
demo QueryForeign KeyInstance /sm:body()/x:Order/x:Delivery/y:TrackingId1Z
Feature: Suggested Item Enhancements – Analysis and Assignment © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and.
Windows Azure SQL Data Sync Name Title Microsoft Corporation.
projekt202 © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
The CLR CoreCLRCoreCLR © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product.
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks.
© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
UNLOCK THE POWER OF USER DEVICE AFFINITY IN SCCM 2012 James SESSION CODE: #SEC309.
CREATING CUSTOM WINPE 3.0 BOOT IMAGES Johan Arwidmark Chief Technical Architect Knowledge Factory SESSION CODE: CLI303 (c) 2011 Microsoft. All rights.
MULTI-TASKING AND APPLICATION SERVICES IN WINDOWS PHONE 7.5 Chris blog.walshie.me SESSION CODE: WPH305 (c) 2011 Microsoft. All rights.
OVER THE FENCE DESIGNER DEVELOPER WORKFLOW Jordan & Alex Knight Directors Xamling SESSION CODE: DEV203 (c) 2011 Microsoft. All rights reserved.

Title of Presentation 11/22/2018 3:34 PM
Domain Driven Design, Domain Events and Unit Testing
Title of Presentation 12/2/2018 3:48 PM
MAP & ACT Pre deployment planning for Windows 7 or Server 2008 R2
DEV422 Becoming a C# Time Lord Joe Albahari 2/5/ :46 AM
(c) 2011 Microsoft. All rights reserved.
The Essential Windows Azure Developers Toolkit
8/04/2019 9:13 PM © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Hyper-V server deployment - Using the right tools
Виктор Хаджийски Катедра “Металургия на желязото и металолеене”
Title of Presentation 5/12/ :53 PM
(c) 2011 Microsoft. All rights reserved.
Шитманов Дархан Қаражанұлы Тарих пәнінің
Title of Presentation 5/24/2019 1:26 PM
Title of Presentation 7/24/2019 8:53 PM
Build /27/2019 © 2015 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION.
Presentation transcript:

THE FUTURE OF C#: GOOD THINGS COME TO THOSE WHO ‘AWAIT’ Joseph Albahari SESSION CODE: DEV411 (c) 2011 Microsoft. All rights reserved.

JOE ALBAHARI (c) 2011 Microsoft. All rights reserved.

ASYNCHRONOUS PROGRAMMING IS THE THEME OF C# 5 (c) 2011 Microsoft. All rights reserved.

Lines of Code – Async Old vs. New (c) 2011 Microsoft. All rights reserved.

Cyclomatic Complexity – Async Old vs. New (c) 2011 Microsoft. All rights reserved.

Part1: all about asynchronous programming Part2: deep dive

History of C# RTM C# 1 Generics C# 2 LINQ C# 3 Dynamic Programming C# 4 Parallel Programming CLR 4 (c) 2011 Microsoft. All rights reserved.

Parallel Programming Task Parallel Library PLINQ (c) 2011 Microsoft. All rights reserved. FW 4.0 Latency Async Functions (C# 5) Rx vNext Concurrency Imperative Functional

Latency is Becoming More of an Issue ► Growth of Internet / Cloud Systems ► Users demand responsive UIs ► Latency has two sources – Compute-bound – I/O-bound (c) 2011 Microsoft. All rights reserved.

What are “Asynchronous Functions” in C# 5? ► New language feature in C# / VB (vNext) ► Deployable CTP ► Patches Compiler, but not CLR ► Small DLL ► Transparent language support for continuations ► Makes asynchronous programming easy (c) 2011 Microsoft. All rights reserved.

“We’re here to help!”

(c) 2011 Microsoft. All rights reserved. “Your call is important to us. Please hold the line!”

(c) 2011 Microsoft. All rights reserved. “Please enter your phone number and press #”

(c) 2011 Microsoft. All rights reserved. “We’ll call you back” Callback 20 minutes later… Continuation

Sync vs. Async Synchronous callAsynchronous call Caller WAITS for method to complete Method returns immediately to caller, and executes callback (continuation) when complete “Blocking”“Non-blocking” (c) 2011 Microsoft. All rights reserved.

Speakerphone ConcurrencyTrue Asynchronous Call Caller manages concurrencyCallee manages concurrency Caller spins up another threadNo threads required (if I/O bound) – and WAITS on that threadNo waiting No callback/continuation required Callback/continuation usually required (c) 2011 Microsoft. All rights reserved.

Async Advantages ► Allows greater efficiency/scalability – Avoids blocking threads ► Caller is freed from plumbing code ► Caller is (usually) freed from thread safety issues ► Can abstract concurrency (c) 2011 Microsoft. All rights reserved.

Waiting is a Synchronous Activity! If you’re waiting, you’re not doing asynchronous programming! What’s the asynchronous equivalent of waiting? (c) 2011 Microsoft. All rights reserved.

What would the simplest possible asynchronous method look like?

string GetWebPage (string uri) {... } void Test() { string html = GetWebPage(“...”); Console.WriteLine (html); } (c) 2011 Microsoft. All rights reserved.

void GetWebPageAsync ( string uri, Action continuation) {... } void Test() { GetWebPageAsync(“...”, Console.WriteLine); } (c) 2011 Microsoft. All rights reserved.

Task GetWebPageAsync (string uri) {... } (c) 2011 Microsoft. All rights reserved.

Task Result property Exception property ContinueWith() method Task is a value-added signaling construct

Task GetWebPageAsync (string uri) {... } void Test() { GetWebPageAsync(“...”).ContinueWith (task => Console.WriteLine (task.Result)); } (c) 2011 Microsoft. All rights reserved.

string GetWebPage (string uri) {... } void Test() { for (int i = 0; i < 5; i++) { string html = GetWebPage(“...”); Console.WriteLine (html); } } (c) 2011 Microsoft. All rights reserved.

Task GetWebPageAsync (string uri) {... } int _i = 0; void Test() { GetWebPageAsync(“...”).ContinueWith (task => { Console.WriteLine (task.Result); if (++_i < 5) Test(); }); } (c) 2011 Microsoft. All rights reserved.

Task GetWebPageAsync (string uri) {... } async void Test() { for (int i = 0; i < 5; i++) { string html = await GetWebPageAsync(“...”); Console.WriteLine (html); } (c) 2011 Microsoft. All rights reserved.

Continuations are the Root Cause of Evil! ► Continuations and imperative code don’t mix! ► This is why we need C# language support aka asynchronous functions (c) 2011 Microsoft. All rights reserved.

Demos ► LINQPad Demo ► VS Project Demo (c) 2011 Microsoft. All rights reserved.

QUESTION & ANSWER SESSION Part1: all about asynchronous programming

► Async functions & TCS ► Compiler translations ► Parallel operations ► Asynchronous Lambdas ► Combinators ► Rx interop (c) 2011 Microsoft. All rights reserved. Part2: deep dive

Thinking asynchronously ► Stop thinking in terms of threads! ► Program synchronously, then await instead of waiting

Guidelines 1.As a rule, await asynchronous methods 2.If you await, make your method asynchronous (return a Task) 3.Don’t block (c) 2011 Microsoft. All rights reserved.

More Demos ► Sockets Demo ► Animation Demo (c) 2011 Microsoft. All rights reserved.

Asynchronous Patterns TAP (Task-Based Asynchronous Pattern) EAP (Event-Based Asynchronous Pattern) APM (Asynchronous Programming Model) (c) 2011 Microsoft. All rights reserved.

Task-Based Asynchronous Pattern ► Very Simple! ► Just one method ► Asynchronous methods should: – have a name ending in ‘ Async ’ – return a Task – (optionally) accept CancellationToken – (optionally) accept IProgress (c) 2011 Microsoft. All rights reserved.

Conclusion ► Asynchronous functions make it easy to do genuine asynchronous programming ► Start applying the TAP now ► Consider consuming AsyncCtpLibrary.dll now (c) 2011 Microsoft. All rights reserved.

Resources ► CTP: download from MS (search “async CTP”) ► MS Async CTP Forum (search “async CTP forum”) ► LINQPad Interactive Async Tutorial (click, ‘download more samples’ from LINQPad) (c) 2011 Microsoft. All rights reserved.

Enrol in Microsoft Virtual Academy Today Why Enroll, other than it being free? The MVA helps improve your IT skill set and advance your career with a free, easy to access training portal that allows you to learn at your own pace, focusing on Microsoft technologies. What Do I get for enrolment? ► Free training to make you become the Cloud-Hero in my Organization ► Help mastering your Training Path and get the recognition ► Connect with other IT Pros and discuss The Cloud Where do I Enrol? Then tell us what you think.

© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. (c) 2011 Microsoft. All rights reserved.