Parallel tasks with EF Core
Parallel Tasks with EF Core Problem: Legacy code runs X tasks in Parallel by using ConfigureAwait(false) and/or Task.Run(() => Parallel.ForEach() which results in errors. Background: ConfigureAwait(true) OR just the regular await commands since ConfigureAwait(true) is the default means that it runs not necessarily on the same thread, but the same synchronization context. ConfigureAwait(false) tells it that it does not need the context, so the code can be run anywhere. It could be any thread that runs it. The problem is that this lack of shared context leads to errors. Error: Because of the nature of parallelism, this error appears inconsistently: "An attempt was made to use the context instance while it is being configured. A DbContext instance cannot be used inside 'OnConfiguring' since it is still being configured at this point. This can happen if a second operation is started on this context instance before ...