I have a general question regarding multithreading in VB.Net. I recently wrote my first program using multithreading; nothing overly complex, just something that reads in a flat text file and performs corresponding inserts/updates on a database. The program used twenty new threads to do this.
Due to the inability to directly pass parameters into or out of the procedure passed to the Thread constructor, I essentially repeated the same code twenty times. Simplifying the process a bit, I created a class with twenty string variables, twenty different connections to the database, and twenty different copies of what was essentially the same code; the only difference between the copies of the code was the string names and the connections used.
When I wanted to fill the database, I'd create a new instance of the class. I'd then read in the twenty lines from the file and fill the corresponding string variables, then kick off the threads. Each thread, using its own connection, would insert the lines into the database.
To get to the point: is there any way to get around the "repeating the same subroutine twenty times" problem? I understand that I can't directly pass parameters into the procedure used in the constructor of the Thread class, but it seems to me that there must be some way around this. My example is pretty simple; in a complex multithreaded example, this seems like it would be a nightmare to maintain. Any changes would have to be repeated in several different locations (the number of locations directly relating to the number of threads desired). Any tips/advice/places to look would be greatly appreciated. Thank you for your time.