0

I know use Async & Await functions better query because not use Main Thread program and You can run Multi Task , but not clear functions when use Async Function must how mach Await function use ?

which query is best for performance and Why ?

Explain My Question by example

Query 1

var sumPagesBooks = _myContext.Books.Sum(b=> b.Page);
var countBooks = awite _myContext.Books.CountAsync();
_context.Books.Add(NewBook);
_context.SaveChange();

Query 2

var sumPagesBooks = awite _myContext.Books.SumAsync(b=> b.Page);
var countBooks = awite _myContext.Books.CountAsync();
_context.Books.Add(NewBook);
awite _context.SaveChangeAsync();

Read This Document but not answered my question

Conclusion

if I use one function async, How mach must i use async function for better performance ?

I thing for all query better way use but i am not sure !!!

Zanyar Jalal
  • 1,407
  • 12
  • 29

1 Answers1

1

because not use Main Thread program

This is not exactly true. "Asynchronous" is different than "parallel".

  • Asynchronous means that one thread will do something different while it waits for something else (like an SQL request). It is about how code waits.

  • Parallel means running two pieces of code at the same time, which can only be done with multiple threads. It is about how code runs.

Asynchronous code can increase your overall performance of your application by doing other work while waiting. But it will actually decrease performance of any one task. But that trade-off is usually better.

That documentation you read is very good at explaining this. I am guessing that English is not your first language, so see if that documentation is available in your language by checking here: https://learn.microsoft.com/en-us/locale/?target=https://learn.microsoft.com/en-us/dotnet/csharp/async

Gabriel Luci
  • 38,328
  • 4
  • 55
  • 84