0

Want to spawn some threads and assign function to each of them later on in a loop.

Spawning the threads with

var threadList = new List<Thread>(); for (int index = 0; index < 3; index++) { threadList.Add(new Thread(() => { })); } 

Now in a loop want to assign function to the threads

for (int index = 0; index < names.Length; index++) { string tempName = names[index]; //check which thread is available //assign a function to the first available thread } 

How do i do it?

If i am using a threadpool: how do i get notified when all the threads are done? how do i stop the threadpool to perform any qction in queue?

1

1 Answer 1

0

Couldn't you just use ThreadPool instead?

System.Threading.ThreadPool.QueueUserWorkItem(myMethod); 

This will assign your methods to an available thread which will be freed up when done.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks for the input.. however isn't there disadvantages of ThreadPool? how can i use a method in ThreadPool.QueueUserWorkItem where the parameter is not of object type?
how do i get notified when all the threads are done? how do i stop the threadpool to perform any qction in queue?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.