Staying Afloat in the .NET Async Ocean

Slides:



Advertisements
Similar presentations
Advanced Troubleshooting with Debug Diagnostics on IIS 6
Advertisements

Parallel Performance Tools in Visual Studio 2010.
Het Asynchrone Microsoft Landschap Kees Dijk Senior Software Developer, Vivens
Parallel Extensions to the.NET Framework Daniel Moth Microsoft
FUTURE OF.NET PARALLEL PROGRAMMING Joseph Albahari SESSION CODE: DEV308 (c) 2011 Microsoft. All rights reserved.
IAP C# Lecture 3 Parallel Computing Geza Kovacs. Sequential Execution So far, all our code has been executing instructions one after another, on a single.
Async Programming WITH ASYNC TASK
Virtual techdays INDIA │ 9-11 February 2011 Parallelism in.NET 4.0 Parag Paithankar │ Technology Advisor - Web, Microsoft India.
Precept 3 COS 461. Concurrency is Useful Multi Processor/Core Multiple Inputs Don’t wait on slow devices.
An introduction to F# (part 2) Bogdan Brinzarea-Iamandi Banca Romaneasca 25 February 2010.
CS533 Concepts of Operating Systems Class 2 Thread vs Event-Based Programming.
CS533 Concepts of Operating Systems Class 2 The Duality of Threads and Events.
Parallel Programming in.NET Kevin Luty.  History of Parallelism  Benefits of Parallel Programming and Designs  What to Consider  Defining Types of.
Joe Hummel, PhD Technical Staff: Pluralsight Adjunct Professor: UIC, LUC
Parallel Extensions A glimpse into the parallel universe By Eric De Carufel Microsoft.NET Solution Architect at Orckestra
Parallel Programming: Responsiveness vs. Performance Joe Hummel, PhD Microsoft MVP Visual C++ Technical Staff: Pluralsight, LLC Professor: U. of Illinois,
About Me Microsoft MVP Intel Blogger TechEd Israel, TechEd Europe Expert C++ Book
SIMPLE PARALLEL PROGRAMMING WITH PATTERNS AND OMNITHREADLIBRARY PRIMOŽ GABRIJELČIČ SKYPE: GABR42
Lecture 21 Parallel Programming Richard Gesick. Parallel Computing Parallel computing is a form of computation in which many operations are carried out.
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 8 Enhancing User Interface Responsiveness.
Plinq Presentation Steen L. Knudsen
Data Parallelism Task Parallel Library (TPL) The use of lambdas Map-Reduce Pattern FEN 20141UCN Teknologi/act2learn.
TAP into async programming
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 4: Threads.
1 Why Threads are a Bad Idea (for most purposes) based on a presentation by John Ousterhout Sun Microsystems Laboratories Threads!
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.
Concepts of Multithreading CS 378 – Mobile Computing for iOS Dr. William C. Bulko.
Chapter 4: Threads Modified by Dr. Neerja Mhaskar for CS 3SH3.
Chapter 4: Multithreaded Programming
Chapter 4: Threads.
Chapter 4: Threads.
Mobile App Development
TechEd /6/2018 6:15 AM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
Advanced Topics in Concurrency and Reactive Programming: Asynchronous Programming Majeed Kassis.
Using Microsoft Visual Basic to Build Windows Phone Applications
Async or Parallel? No they aren’t the same thing!
Chapter 4: Multithreaded Programming
Lighting Up Windows Server 2008 R2 Using the ConcRT on UMS
Getting Started with Visual Studio Tools for Tizen
Task Parallel Library: Design Principles and Best Practices
Microsoft Build /14/ :29 PM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY,
C++ Forever: Interactive Applications in the Age of Manycore
Chapter 4: Threads.
12 Asynchronous Programming
Operating System Concepts
Asynchronous Programming in .NET
Chapter 4: Threads.
Getting Started With TypeScript
12/2/2018 4:10 AM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Application Insights Diagnostics Preview
F# for Parallel and Asynchronous Programming
TechEd /9/2018 4:17 AM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
Open sourced Power BI visuals The power you need for your custom visualization needs Lukasz Pawlowski Senior Program
Tiberiu Covaci Senior Technical Trainer Many-core
Visual Studio 2010 and .NET Framework 4 Training Workshop
Build /2/2019 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
DEV422 Becoming a C# Time Lord Joe Albahari 2/5/ :46 AM
Azure Functions & Aurelia Serverless SPAs
Hold up, wait a minute, let me put some async in it
Microsoft Connect /24/ :10 PM
Microsoft Build /27/2019 2:26 PM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY,
Operating System Introduction.
Chapter 4: Threads & Concurrency
- When you approach operating system concepts there might be several confusing terms that may look similar but in fact refer to different concepts:  multiprogramming, multiprocessing, multitasking,
Chapter 4: Threads.
Server & Tools Business
CMSC 202 Threads.
Lecture 20 Parallel Programming CSE /8/2019.
Presentation transcript:

Staying Afloat in the .NET Async Ocean Mike Huguet Senior Premier Field Engineer CRM and Developer Support

Mike Huguet Senior Premier Field Engineer CRM and Developer Support

Objective Feel comfortable in making a decision of which pattern and constructs to use

Agenda Threading Basics Async Programming Parallel Programming

Agenda Threading Basics Async Programming Parallel Programming

Asynchronous vs. Parallel Dealing with a lot of things at once Responsive User Interface Prevent blocking Can delegate to another A.k.a.-concurrency Parallel Doing a lot of things at once Requires asynchronous Break up work or tasks

Example - Juggling

What is a thread? Unit allocated to processor time by the OS PRISM FY16 Unit allocated to processor time by the OS Multiple threads can be allocated per process The OS and .NET create the effect of simultaneous thread execution 11/14/2018 2:53 PM What is a thread? First, let’s level set on what culture is. Culture is an outcome, it is the result of how we behave and work in our system. It is guided by decisions and what is reinforced. © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Threading disadvantage? PRISM FY16 Can strain OS resources and degrade performance Overhead exists for managing and using threads Cross thread communication costs Can require resource synchronization Adds complexity to code and is a high cause of bugs (e.g.-deadlocking, race conditions) 11/14/2018 2:53 PM Threading disadvantage? First, let’s level set on what culture is. Culture is an outcome, it is the result of how we behave and work in our system. It is guided by decisions and what is reinforced. © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Threading benefits? Effective way to increase responsiveness PRISM FY16 Effective way to increase responsiveness 11/14/2018 2:53 PM Threading benefits? First, let’s level set on what culture is. Culture is an outcome, it is the result of how we behave and work in our system. It is guided by decisions and what is reinforced. © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Agenda Threading Basics Async Programming Parallel Programming

Asynchronous Programming Patterns Legacy System.Threading Async Programming Model (APM) Task-based Async Pattern (TAP) ***Modern Event-Based Async Programming Model (EAP)

System.Threading - Thread ThreadStart Notes .NET 1.0 Expensive Risky Can be complex *Use ThreadPool. QueueUserWorkItem $$$

System.Threading - ThreadPool Notes Managed a pool Handles multi-CPU Difficult for continuation Single param restriction $$$

Demo - Threading

Async Programming Model (APM) BeginXxx EndXxx IAsyncResult Notes .NET 2.0 Supports continuation Uses IO OS Threads Supports cancellation Expensive Can be complex continuation

Demo – APM

Event-Based Async Programming Model (EAP) XxxAsync XxxCompleted XxxCancelled Notes .NET 2.0 Expensive Risky Can be REALLY complex BackgroundWorker WebClient

Demo - EAP

Task-based Asynchronous Pattern (TAP) XxxAsync Task.Run Task.Factory .StartNew Task<TResult> CancellationToken IProgress Notes .NET 4.0 Single method Supports multiple typed params Supports typed result Supports continuation & Cancel

Demo – TAP

TAP – Async/Await XxxAsync Task Task<TResult> Progress Notes .NET 4.5 Much easier continuation Compiler sugar Can be confusing Finally blocks might not run

Demo – Async/Await

Agenda Threading Basics Async Programming Parallel Programming

Task Parallel Library (TPL) Parallel.For Parallel.ForEach Parallel.Invoke Dataflow Blocks Notes .NET 4.0 Not always async Extra overhead

Parallel LINQ (PLINQ) ParallelQuery AsParallel Notes ParallelEnumerable ParallelQuery AsParallel Notes .NET 4.0 Familiar LINQ syntax Tries to optimize loading on multiple threads and cores Not necessarily faster

Demo – Parallel

Resources Parallel Processing and Concurrency in the .NET Framework - https://msdn.microsoft.com/en-us/library/hh156548(v=vs.110).aspx Managed Threading Best Practices - https://msdn.microsoft.com/en-us/library/1c9txz50(v=vs.110).aspx Managed Threading Basics - https://msdn.microsoft.com/en-us/library/hyz69czz(v=vs.110).aspx The Asynchronous Programming Models - http://blogs.msdn.com/b/mazhou/archive/2011/10/04/the-asynchronous-programming-models.aspx Asynchronous Programming with Async and Await - https://msdn.microsoft.com/en-us/library/vstudio/hh191443.aspx Parallel Programming in the .NET Framework - https://msdn.microsoft.com/en-us/library/dd460693(v=vs.110).aspx