I have a question regarding multithreading. I currently have a Vb.net project that I’m running under the main thread. Everything works well but I want to make some changes to it to make it more user friendly. The app is used to batch run files through a post processor. The user starts out by selecting a folder where all the files reside. The app then parses the folder to find files that match a certain file extension. If the file extension matches, the app, loads the file name into a Non-bound datagridview. The datagridview also contains a checkbox column that user can use to either select or deselect a certain file. The user selects all the files to run using the checkbox column and then hits the post process button to start the batch run. The program then loops through the datagridview and finds all the files that have been selected and runs them through a 3rd party post processor. After the file has been post processed, the app reads a log file created by the post processor to see if any errors occurred. After reading the log file, the app updates an “error” column in the datagridview. Upon completion, the program starts the loop over again with the next file.
Everything in the app works great except for one thing. Once the loop has started, it is impossible for the user to stop the process mid stream because everything is running on the main thread. I have done some very simple multithreading apps in the past so I tried to switch the post processor “process” over to an external thread. I was able to get the app to post process the file via the thread but when running multiple files, the app now wants to start up a process for each file in the loop. The issue I have with this is that we only have a limited number of post processor licenses so I don’t want the app to start up more than one more thread at one time. If I tell the main thread to wait until the post processor process is complete, the main thread will no longer be responsive for GUI interaction if the operator wants to stop the process. How do I set up my app to remain responsive to GUI interaction while running the post processor operation? I was thinking about moving my entire loop to the external thread but I don’t know if that is the correct direction to go or not?