Async programming
Async Programming
Obviously only do these in methods that are marked async.
1) Instead of .ToList() think about .ToListAsync(cancelToken).Result; This does not apply to IEnumerable that does not have an ToListAsync(). IQueryable does have it.
2) Instead of .FirstOrDefault(), think about .FirstOrDefaultAsync(cancelToken).Result;
Love this article:
https://learn.microsoft.com/en-us/dotnet/csharp/asynchronous-programming/
This is ok:
https://learn.microsoft.com/en-us/dotnet/csharp/asynchronous-programming/async-scenarios
Comments
Post a Comment