I have a set of SQL commands that don't return a query, only the amount of affected records. They run in different servers.
They can run simultaneously, I don't need to wait one finish to start another. I'm developing a C# app, I'd like to execute them all in parallel, and then wait for them all to finish and get their int returns.
The first idea is to use multiple threads. I create a thread to run each SqlCommand.ExecuteNonQuery()
. Maybe I create a list of bools, that are set to true when the execution finishes. Then, on the main thread, I keep verifying these bools and sleep if any of them is false. A try-finally would set the bool to true even if an Exception is thrown.
Is that the best solution? Can anybody think a better way to do it?