private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < 15; i++)
{
Thread nova = new Thread(Method);
nova.Start();
}
listBox1.Items.Add("Some text");
}
private void Method()
{
for (int i = 0; i < 15; i++)
{
Console.WriteLine(i);
}
}
This code does write: Some text and then numbers 111222333…..
I would like that it writes 111122223333…. and then on the end Some text.
is it possible to do that with threads (parent thread wait for child threads)? or do i have to use something else?
I suggest to use TPL to get this done. You won’t need to spawn so many threads. By default TPL will use thread pool for that: