Share via


Array of Threads

Question

Tuesday, August 8, 2006 8:43 PM

Hello,

Beginner question... i want to use an array of:

ThreadStart[] job = new ThreadStat ...

Thread[] thread = new Thread ......

so i will have lets say 10 threads that i can start/sleep, and to decide when to run each of them. how do i write this down?

All of them will run the same method. so i need to define an array of 10 threads

and how do i start each of them?

 

Thank you!

All replies (5)

Tuesday, August 8, 2006 9:46 PM âś…Answered

Does this help?

 



Thread[] theThreads = new Thread[Number];
 
for (int counter = 0; counter <= Length; counter++)
{
   theThreads[counter] = new Thread(new ThreadStart(MethodName));
}

 

Wednesday, August 9, 2006 10:12 AM

sorry for the stuiped question but i'm trying to start a tread but i get this error:

Error 1 Only assignment, call, increment, decrement, and new object expressions can be used as a statement C:\DBC\Moty\HttpTesting\HttpTesting\Program.cs 29 21 HttpTesting

thread[NumberOfRunningThreads].Start;

 

Thank you.


Wednesday, August 9, 2006 11:38 AM

you forgot the brackets at the end I believe ()

is the code you have the same as what I have posted?


Wednesday, August 9, 2006 12:40 PM

Thanks, you could never see you own mistakes.. :)

 

yes it's your code, 10x.


Wednesday, August 9, 2006 1:09 PM

cool! Glad I could help :-)