Async Programming WITH ASYNC TASK

Slides:



Advertisements
Similar presentations
Asynchronous Programming with C# and WinRT
Advertisements

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.
Chapter 7 Protocol Software On A Conventional Processor.
Chapter 4: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP Threads.
ECE 526 – Network Processing Systems Design Software-based Protocol Processing Chapter 7: D. E. Comer.
An introduction to F# (part 2) Bogdan Brinzarea-Iamandi Banca Romaneasca 25 February 2010.
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 4: Threads Dr. Mohamed Hefeeda.
Process Concept An operating system executes a variety of programs
Multithreading.
Interesting facts about node.js.  Asynchronous I/O  How do they do that?..threads (usually) What do Web Servers do?
Parallel Processing (CS526) Spring 2012(Week 8).  Thread Status.  Synchronization in Shared Memory Programming(Java threads ) ◦ Locks ◦ Barriars.
Node.js - What is Node.js? -
Quick overview of threads in Java Babak Esfandiari (extracted from Qusay Mahmoud’s slides)
Consuming REST Services from C# SoftUni Team Technical Trainers Software University
Processes & Threads Bahareh Goodarzi. Single & Multiple Thread of control code files data code files data.
Parallel Programming: Responsiveness vs. Performance Joe Hummel, PhD Microsoft MVP Visual C++ Technical Staff: Pluralsight, LLC Professor: U. of Illinois,
Joe Hummel, PhD Microsoft MVP Visual C++ Technical Staff: Pluralsight, LLC Professor: U. of Illinois, Chicago stuff:
ADVANCED WEB SERVICES. Three Advanced Web Service Techniques SOAP Extensions Asynchronous calls Custom wire formatting SOAP Extensions Asynchronous calls.
Copyright ©: University of Illinois CS 241 Staff1 Threads Systems Concepts.
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.
C20: Threads see also: ThreadedBallWorld, DropTest, Tetris source examples Not covered: advanced stuff like notify/notifyAll.
Chapter 4 – Threads (Pgs 153 – 174). Threads  A "Basic Unit of CPU Utilization"  A technique that assists in performing parallel computation by setting.
15.1 Threads and Multi- threading Understanding threads and multi-threading In general, modern computers perform one task at a time It is often.
Asynchronous Programming Writing Asynchronous Code in C# SoftUni Team Technical Trainers Software University
Discussion Week 2 TA: Kyle Dewey. Overview Concurrency Process level Thread level MIPS - switch.s Project #1.
Multithreaded Programing. Outline Overview of threads Threads Multithreaded Models  Many-to-One  One-to-One  Many-to-Many Thread Libraries  Pthread.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Concurrency & Dynamic Programming.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
1 OS Review Processes and Threads Chi Zhang
TAP into async programming
2/20/2016 EEC492/693/793 - iPhone Application Development 12/20/2016 EEC492/693/793 - iPhone Application Development 1 EEC-492/693/793 iPhone Application.
Unit 4: Processes, Threads & Deadlocks June 2012 Kaplan University 1.
Operating System Concepts
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Lecture 6: Process and Threads Topics: Process, Threads, Worker Thread, Async Task Date: Mar 1, 2016.
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.
R Some of these slides are from Prof Frank Lin SJSU. r Minor modifications are made. 1.
Lecturer 3: Processes multithreaded Operating System Concepts Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess.
Asynchronous Programming Writing Concurrent Code in C# SoftUni Team Technical Trainers Software University
Threads by Dr. Amin Danial Asham. References Operating System Concepts ABRAHAM SILBERSCHATZ, PETER BAER GALVIN, and GREG GAGNE.
The Future of C# and Visual Basic
Advanced Topics in Concurrency and Reactive Programming: Asynchronous Programming Majeed Kassis.
Thread Fundamentals Header Advanced .NET Threading, Part 1
Advanced C++ Programming
Async or Parallel? No they aren’t the same thing!
Chapter 4: Multithreaded Programming
Nachos Threads and Concurrency
Threads & multithreading
Operating System Concepts
Staying Afloat in the .NET Async Ocean
O.S Lecture 13 Virtual Memory.
12 Asynchronous Programming
Creating Windows Store Apps Using Visual Basic
Cs561 Presenter: QIAOQIAO CHEN Spring 2012
Chapter 26 Concurrency and Thread
Multithreading.
TechEd /9/2018 4:17 AM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
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.
Threads and Concurrency
Android Topics Asynchronous Callsbacks
Multithreaded Programming
Hold up, wait a minute, let me put some async in it
Building Web Applications with Microsoft ASP
Outline Chapter 3: Processes Chapter 4: Threads So far - Next -
03 | Async Programming & Networking Intro
Ch 3.
Synchronization and liveness
Presentation transcript:

Async Programming WITH ASYNC TASK

Responsiveness File operation - If system is busy with I/O, file operation is bound to be slower. Web services – web services by very nature are unpredictable. Similarly access other web resources might have the same issue. o Use of async prevents system from blocking the UI thread. When the data is available, the rest of the operation can continue. o Async await mechanism gives the same benefits without additional overhead with other methods (async event or use of threads) o Async await code executes on the same thread and not on independent thread. o Use Task.Run to move CPU intensive work to background thread.

Easy to use async and await make.NET and WinRT API consumeable from within your code. They make asynchronous code as easy to create and use as synchronous code async methods  Method signature contains async keyword.  Method name ends with Async (though this is just a naming convention and not a requirement)  Contains Task or Task or void return types  Contains at least one await expression.

So what really happened there ? A method that is marked as async results in creation of an additional structure. This structure implements IAsyncStateMachine The MoveNext method contains the implementation of the async method. As you can see async does not result in thread creation. The async code is executed on the same thread as the one that initiated it. This makes async task based code easy to write and consume as one does not deal with multiple threads and thread synchronisation issues etc. This also means that for CPU bound operations, one needs to do a bit more work.

Running async on different thread ? Task.Run ThreadPool.RunAsync Both an awaitable task so one can wait for the async task running on another thread. What is the difference ? Task.Run is uses.NET async task mechanism and.NET ThreadPool. ThreadPool.RunAsync is a WinRT implementation. Unless you have a specific need, one should use Task.Run as it is tried and tested code.

What about Task.Wait ? It’s a blocking call. If UI thread is executing the task, called Wait / WaitAny / WaitAll will kill the app. Should try and use non-blocking WhenAny / WhenAll Can be used when using non UI thread for task execution.. Within Task.Run / ThreadPool.RunAsync