'Background parallel process of SQL queries in C#

I'm working on a small C# tool that processes lot of SQL statements.

The GUI features tools to generate and display a queue of SQL statements. I want to process them in parallel, control the maximum number of parallel queries on the fly (when reduced).

  • Some SQL queries return result sets.
  • It must spawn just the one connexion per worker and reuse them for next task
  • It must be able to pause/restart the processing of the queue gracefully
  • It must support increase/decrease the number of simultaneous tasks while processing
  • The GUI shows the current progress (the list of what is running)
  • I would rather use Tasks (single physical thread) instead of threads

What is the best way to do it ?

I found several questions about parallel workers, but no answer shows how to report progress.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source