I have a class in a windows form app, that takes a file name that is used to call a web api returns some data and inserts it into a database. I call this in my main class after geting an array of file names. When I run the program like:
foreach(String M_file in files)
{
FileTODataBase ftb = new FileToDataBase(M_file);
}
It works fine. If I move the FileToDataBase
to method(object a)
and call it in the loop like ThreadPool.QueueUserWorkItem(method, M_File);
foreach(String M_File in files){
ThreadPool.QueueUserWorkItem(method, M_File);
}
private void method(object a){
String M_Files = a as String;
FileToDataBase ftb = new FileToDataBase(M_Files);
}
It only works for my test folder of 6 files. When running it on the full folder of 800+ items it does not appear to do anything. It does not freeze just does not appear to do any of the actual work of inserting or calling the api. I have read some other post about using thread pools and Task but have been unable to get any of the implementations to work.