Posts

Showing posts with the label multitasking

What's in a Task?

Introduction Tasks in .NET have become ubiquitous: by now we all know that in order to make our apps and services more scalable (not necessarily performant, they are different concepts), we need to use them. A task is an operation that is designed to run in the background and which may or may not return a value. Tasks allow complex operations (I/O or CPU-bound) to be executed without blocking the main thread and are implemented by the Task  and  Task<T>  classes. These are actually monads  in mathematical and functional terminology, which means they have certain properties which I won't cover here. There are two ways by which we can call a method that is meant to be processed by another thread (one that returns  Task  or Task<T> , which inherits from  Task  but wraps a result): We use  await  to ask for the callee to be called by another thread and wait for its completion We omit  await  and have the callee processi...