S
S
super152018-08-12 13:07:37
C++ / C#
super15, 2018-08-12 13:07:37

Why is Async Await needed in C#?

I don’t understand why to use async await, I re-read many articles, but I didn’t understand the meaning.
After all, the result is the same if the method is not made asynchronous.
Or, is it only necessary to not freeze the main thread, but at the same time not continue execution until the secondary thread is completed?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Eugene, 2018-08-12
@super15

Asynchrony is about performance concurrency. Multithreading is about multiple threads.
Asynchrony - you woke up, put the kettle on, went to the shower. Heard a squeak - returned, made tea and continued to brush his teeth.
Multithreading - it's you who woke up, went to the shower, and your girlfriend put the kettle on.

G
Griboks, 2018-08-12
@Griboks

This is a sugar that freezes the current execution position in the method while the asynchronous method is running. It replaces creating a thread, starting a thread, calling a callback when the thread ends. It also allows you not to highlight the underlying code in the coolback method.

C
chibitko, 2018-08-14
@chibitko

async / await is needed for optimal use of system resources, there are two types of tasks - I / O tasks and multithread tasks, and so with IO operations it makes no sense to keep the current thread, you can let those who need it use the CPU resources, and so before you had to use IAsyncResult , it was inconvenient, now there is syntactic sugar for it and a unified approach to working with asynchrony and multithreading

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question