.net core - Passing an unknown number of IProgress<T> to class library

.net core - Passing an unknown number of IProgress<T> to class library

I have a console app which uses a class library to execute some long running tasks. The console app is unaware of how many tasks the library executes (some of which run in parallel). I need to be able to report the progress of each task within the console application. The call from my console app looks something like this

I have a console app which uses a class library to execute some long running tasks. The console app is unaware of how many tasks the library executes (some of which run in parallel). I need to be able to report the progress of each task within the console application. The call from my console app looks something like this

public Task StartAsync(CancellationToken cancellationToken)
{
    _myServiceFromLibrary.RunTasks();

return Task.CompletedTask;

}

And in my my class library, the implementation is something along the lines of

public void RunTasks()
{
    var taskList1 = new List<ITask> { Task1, Task2 }:
    var taskList2 = new List<ITask> { Task3, Task4, Task5 }:

taskList1.foreach( task =&gt; task.Run() );

Parallel.Foreach(taskList2, task =&gt; { task.Run() });

}

Now, I want to pass a collection of IProgress<T> to the RunTasks() method which I can then iterate over and display the progress individually on the console. These are then passed by RunTasks() to each task's Run() method so the task can report it's own progress back.

However, to be able to know how many instances I need to pass, I am using a dirty hack where the class library exposes a TaskListCount which I use to generate those many IProgress<T> to send to RunTasks().

Is there a better way to do this? I am really only after being able to get the progress updates from RunTasks() somehow, even if it is without using IProgress.

Any help much appreciated.

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Add asp.net Identity in empty project

LIKE | COMMENT | SHARE | SUBSCRIBE Today, in this tutorial you will see the process of adding an ASP.NET Identity to the ASP.NET Web Application developed in...

List all users from asp net core identity

LIKE | COMMENT | SHARE | SUBSCRIBE In this video, i will show you How to retrieve and display all the registered application users in asp.net core using the ...

Extend IdentityUser in ASP NET Core

LIKE | COMMENT | SHARE | SUBSCRIBE In this tutorials, I will show you how to extend IdentityUser in asp.net core.. Subscribe & Stay Connected! Thank You! ♥ #...