I have to proccess Gb of files and send them to the network using a library that has async methods to perform this kind of operations.
If I do the following, I think I will get an infinite thread number working at the same time if they take a while to complete:
void ProcessFiles()
{
string[] files = /*a lot of files */
foreach(file in files)
{
MyAsyncMethod(file)
}
}
async void MyAsyncMethod(string file)
{
string conent = File.ReadAllBytes(file);
await MyLibrary.Async(call)
}
Of course it should be a limit in the number of concurrent threads running, but several threads will be created and performance will get worse... It should be a limit to create threads... what happens when this limit is reached? The new threads will be created after the current ones end? The will be ignored? The program will throw an exception??
How can I manage this "inifinite" number of async calls. Should I convert it to sync calls (Task.start() + Task.wait()) and manage it by my own thread pool?
Thank you