When creating methods using the async / await model, the entire call chain should be created using the async / await model. In other words, async / await should be cross-cutting . for example
async Task<int> FirstMethod() { await Task.Delay(100); return 1; } async Task<int> SecondMethod() { await Task.Delay(100); return 2; } async Task<int> UseBothMethods() { var first = await FirstMethod();//Π’Π΅ΠΊΡΡΠΈΠΉ ΠΏΠΎΡΠΎΠΊ Π²ΡΡΠ²ΠΎΠ±ΠΎΠΆΠ΄Π°Π΅ΡΡΡ ΠΈ ΠΌΠΎΠΆΠ΅Ρ Π·Π°Π½ΡΡΡΡΡ ΡΠ΅ΠΌ-ΡΠΎ Π΅ΡΠ΅, ΠΏΠΎΠΊΠ° FirstMethod() Π½Π΅ Π²Π΅ΡΠ½Π΅Ρ Π·Π½Π°ΡΠ΅Π½ΠΈΠ΅ var second = await SecondMethod();Π’Π΅ΠΊΡΡΠΈΠΉ ΠΏΠΎΡΠΎΠΊ Π²ΡΡΠ²ΠΎΠ±ΠΎΠΆΠ΄Π°Π΅ΡΡΡ ΠΈ ΠΌΠΎΠΆΠ΅Ρ Π·Π°Π½ΡΡΡΡΡ ΡΠ΅ΠΌ-ΡΠΎ Π΅ΡΠ΅, ΠΏΠΎΠΊΠ° SecondMethod() Π½Π΅ Π²Π΅ΡΠ½Π΅Ρ Π·Π½Π°ΡΠ΅Π½ΠΈΠ΅ return first+second; }
If the UseBothMethods method is created without using async / await, then we will have to wait for the FirstMethod and SecondMethod execution, thereby suspending (freezing) the execution flow.
Task<int> UseBothMethods() { var first = FirstMethod().Result; // ΠΆΠ΄Π΅ΠΌ 100 ΠΌΡ ΠΏΠΎΠΊΠ° Π²ΡΠΏΠΎΠ»Π½ΠΈΡΡΡΡ ΠΌΠ΅ΡΠΎΠ΄. ΠΠΎΡΠΎΠΊ Π·Π°ΠΌΠΎΡΠΎΠΆΠ΅Π½ ΠΈ Π½ΠΈΡΠ΅Π³ΠΎ Π½Π΅ Π΄Π΅Π»Π°Π΅Ρ var second = SecondMethod().Result;// ΠΆΠ΄Π΅ΠΌ 100 ΠΌΡ ΠΏΠΎΠΊΠ° Π²ΡΠΏΠΎΠ»Π½ΠΈΡΡΡΡ ΠΌΠ΅ΡΠΎΠ΄. ΠΠΎΡΠΎΠΊ Π·Π°ΠΌΠΎΡΠΎΠΆΠ΅Π½ ΠΈ Π½ΠΈΡΠ΅Π³ΠΎ Π½Π΅ Π΄Π΅Π»Π°Π΅Ρ return first+second; }
If async / await is not done end-to-end, it will disrupt the use of the pattern and will deprive us of the benefits of asynchronous waiting for the execution of "long" methods, which is to release the thread to do any work.
Now I will explain how all this relates to the current issue. The answer is, if you create async / await end-to-end, as it should be, then questions on the type of what the author had, simply will not arise.