Please enable JavaScript.
Coggle requires JavaScript to display documents.
Asynchronous Programming (Task and Task<T> (Exposes an API protocol,…
Asynchronous Programming
Task and Task<T>
-
-
By default, executes on the current thread and delegate work to the Operating System as appropiate
Can run on seperate thread, use Task.Run API
Exposes an API protocol
-
-
-
Await keyword
Allows you application or service to perform useful work while a task is running by yielding control to its calles until the task is done
Your code does not need to rely on callbacks or events to continue execution after the task has been completed
-
If you are using Task<T> the await keywork will additionally "unwrap" the value returned when the Task is complete
Language integration, with the await keyword, provides a higherlevel abstraction for using tasks
-
-
async void, only for event handlers
For I/O bound code you await an operation, which returns Task, inside of an async method
For CPU-bound code, you await an operation which is started on a background thread with the Task.Run method
-
-
CPU-bound async code
-
Using asyng and await provieds a clean way to interact with a background thread and keep the caller of the async method responsive
Does NOT provide any protection for SHARED DATA. Apply appropriate synchronization strategy if you are using shared data
Usage
Any I/O needs
-
-
CPU, performing an expensive calculation
-
Best practises advice
-
-
-
When using async always await, or they will never yield
-
-
-