March 8th, 2010, 09:43 AM
Threadpool & Generic Lists
Well I've got the basis of using single threads to process a piece of logic within my code, however I'm not certain about the threadpool. Below is a pseudo style example of what I'd like to achieve.
Obviously this code wouldn't work in reality, I think there needs to be some sort of logic to lock threads accessing the same string and add a new string (race condition). Also within the EditStrings method, external fuctions might be called, so the same may apply to this, and there needs to be a method of passing the a string into the EditStrings method, however it will only accept one parameter argument, so maybe using delegates would be nice.
private List<string> ManyStrings = new List<string>();
private List<string> ProcessedStrings = new List<string>();
for (int i = 0; i < ManyStrings.Count; i++)
static void EditStrings(object state)
// lots of string manipulation here
New to C#
| Using VS 2008 with 3.5.
March 8th, 2010, 12:12 PM
Re: Threadpool & Generic Lists
The one parameter is of type object. All .NET types derive from System.Object, therefor, you can create a struct or a class which contains multiple properties/members. Construct said class, pass it in as the 'object' parameter to your thread. Then, within your thread method (ie: EditStrings), cast the parameter to the class type you created and extract the members from there.
Click Here to Expand Forum to Full Width