I\'ve been reading a lot about threading but can\'t figure out how to find a solution to my issue. First let me introduce the problem. I have files which need to be processe
I think ThreadPool is the perfect solution for you. It will handle the threads by itself and queue their work. Moreover, you can set the maximum threads limit and it will still queue your work even if you have more than the maximum number of threads.
ThreadPool.SetMaxThreads([YourMaxThreads],[YourMaxThreads]);
foreach (var t in host_thread)
{
ThreadPool.QueueUserWorkItem(Foo, t);
}
private static void Foo(object thread)
{
foreach (var file in (thread as host_file_thread).group_file_paths)
{
(thread as host_file_thread).process_file(file);
}
}
Although I would suggest you change your data structure and keep the process_file
method from it