WhenAllでTaskを呼ぶとキューを順次実行するのではなく同時に並行実行するため、DBの排他制御時など同時実行が不可能な処理を含む場合は注意。
当然実行順序も保証されない。
EFcore参照でawaitしている場合に以下のような例外が発生した。
System.InvalidOperationException: A second operation was started on this context before a previous operation completed. This is usually caused by different threads concurrently using the same instance of DbContext. For more information on how to avoid threading issues with DbContext, see https://go.microsoft.com/fwlink/?linkid=2097913.
at Microsoft.EntityFrameworkCore.Internal.ConcurrencyDetector.EnterCriticalSection()
at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
なかなかこの情報にたどり着けなかったので個人的な備忘録を残しておく。
横着せず一件ずつ実行してしまえば解決する。