In a lot of discussions about C#'s async/await, I see people mention the term "naturally asynchronous" or "pure asynchronous". What exactly do these terms mean?
What are some examples of a "naturally asynchronous" operation and why is it called so?
What are some examples of a "non-naturally asynchronous" operation, and why?
Asynchronous in computer programming In computer programming, asynchronous operation means that a process operates independently of other processes, whereas synchronous operation means that the process runs only as a result of some other process being completed or handed off.
BeginInvoke returns an IAsyncResult, which can be used to monitor the progress of the asynchronous call. The EndInvoke method retrieves the results of the asynchronous call. It can be called any time after BeginInvoke . If the asynchronous call has not completed, EndInvoke blocks the calling thread until it completes.
Asynchronous programming can help systems run more effectively, depending on the situation and often prevents long wait times. For example, if a task you want to perform uses a lot of input and output, asynchronous programming lets other tasks run, whereas synchronous programming would create a time block.
Asynchronous functions are often found in front end applications and used particularly in independent, high volume, IO tasks. Front end applications benefit from its use because it enhances the flow of an application. Backend processes may use asynchronous functions to run many tasks or make lots of network calls.
It's almost always I/O.
Naturally asynchronous operations are operations that don't require the CPU, like sending data over the network or reading data from the hard drive. They don't require any computations so the CPU can do other tasks while they run.
There are also logical operations that don't require a thread, for example waiting for a timeout to expire, or wait on synchronization constructs (e.g. AsyncLock
)
Operations that are asynchronous but not naturally asynchronous are CPU operations being executed on a background thread. These are useful for responsiveness (e.g. For UI apps) but don't improve performance or scalability as they still require the same amount of resources.
So you have:
Naturally asynchronous operations running asynchronously:
await Task.Delay(1000);
Naturally asynchronous operations running synchronously:
Thread.Sleep(1000);
Naturally synchronous operations running asynchronously:
await Task.Run(() => CalculateSquareRoot(5));
Naturally synchronous operations running synchronously:
CalculateSquareRoot(5);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With