Hi I want to create a new thread for each item in a numericupdown. I want each thread to perform an object. I have this code, but Im not sure if its correct. Please check:

for (int i = 0; i < numericUpDown1.Value; i++)

Thread t = new Thread(new ParameterizedThreadStart(myParamObject));


Also, another question I have is Im calling a listBox created in another thread so how can I incorporate it so I wont get a cross thread error?

Edited by kytro360: n/a

6 Years
Discussion Span
Last Post by Momerath

It will work but your threads will go out of scope as soon as the for statement is done. You are also starting them as foreground threads which means your program won't close until they are done. If that's the behavior you want, then you are good. But I'd look into Parallel.For() as it attempts to optimize thread usage based on your systems processor and capabilities.

As for using the ListBox from another thread, read this.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.