Quote:
just wait on the last one to finish
That is a bit of confusing statement. How do you say which is the last one? Do you have a reference to the last one in a Task variable? Or, you have a list of them, and you just want to see when all of them have completed? Well, both of these can be solved easily using the TPL (Task Parallel Library).
var lastTask = something;
lastTask.Wait();
This will wait only for the last task, if any other tasks are pending, it will skip. However, a better alternative is, to have a
List<Task>
and have the
Task
function for the
WhenAll
to be called on it.
var list = allTasks;
Task.WhenAll(list).Wait();
You are already consuming async/await pattern, so you know that async and await approach is better. But somehow you also seem to be a bit confused in this,
Quote:
Thought we could use Async/Await only and no backgroundworkers nor tasks.
Async/await pattern in C# is based on Task (System.Threading.Tasks namespace). So, I don't think you can apply anything with async/await, and skip the
Task
type. :-)
Task.WhenAll Method (System.Threading.Tasks) | Microsoft Docs[
^]
Quote:
10 SELECTs simultaneously.
That's like 10 new requests to the Azure SQL Database, 10 connections (even though backend can utilize connection pooling), and then an overhead of the threads, thread pools and context switching. I am unsure as to how this could have improved the overall startup time and performance. Yes, it can improve responsiveness and scalability, and utilize the thread pool threads, but, still. 10 SELECT commands are going to take the same amount of time they are going to take in sync version, but yes, resource creation is going to be a lot cheaper in asynchronous approach.