I'm building an app that will schedule some jobs with Hangfire. They will from time to time execute at the same time. Each jobs has number of "configs" to process. To speed up things it is executing using Parallel.ForEachAsync.
I'm looking for a way to control number of threads/tasks that can be used by those ForEachAsync calls.
I this I'm going in a wrong direction since ParallelOptions are specified once and cannot be adjusted if number of available threads will change.
I was also thinking about Semaphore but cannot figure it out.
Maybe a Singleton service registered that would hold info about number of available threads and then each hangfire job would use it to decide how many "configs" it can execute in parallel.
I'm looking for an advice on this, of course code samples are more than welcome.