Search code examples
c#winformsbackgroundworker

Is it possible to programmatically create BackgroundWorkers?


I'm trying to let user choose amount of threads that can be used to perform a task by using background workers.

Is there any way to automatically create up to 250 background workers?


Solution

  • Based on your comments, I think you would be better off using C# Tasks.

    See: http://msdn.microsoft.com/en-us/library/system.threading.tasks.taskscheduler.aspx

    The example even shows an example of 500 tasks.

    That way you can simply set the MaximumConcurrencyLevel in order to provide the functionality you are looking for.

    BackgroundWorkers aren't good for your task, C# Tasks are going to be better. The TaskScheduler is going to be far more efficient.