Click here to Skip to main content
15,850,685 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi friends,

I want help to create 10 Threads, and when these threads end work they will be killed, and after I create another 10 execute the same methode and like that...
every time i have to do this,

jim lahey 20-Sep-11 11:09am    
and have you tried anything yet?
Rob Philpott 20-Sep-11 11:21am    
Why kill them when they're finished? Why not reuse them?
Sergey Alexandrovich Kryukov 20-Sep-11 16:52pm    
Right. The same way you could ask: why 10 threads, not 8 or 512? Some sloppy design not based on anything rational.

Threads are expensive resources, and you should create and reuse them.

See the following link on ThreadPools and How to: Use a Thread Pool (C# Programming Guide)
Share this answer
create a List<thread> myThreadPoolOfTen = new List<thread>();

with a foreach (Thread thread in myThreadpoolOfTen) you can follow if thread.IsActive is false. In that case you can add a task to the thread.

Have Fun
Share this answer
pablo ramos1 20-Sep-11 11:19am    
Thank you digimanus for your help, give me an exemple please !!!
Herman<T>.Instance 20-Sep-11 11:20am    
can you show your source so I can see the objects you use. I can then setup a ThreadPool for you
pablo ramos1 20-Sep-11 13:49pm    
No, just a Method :

public void do()
Ping pingSender = new Ping();
PingOptions options = new PingOptions();

// Use the default Ttl value which is 128,
// but change the fragmentation behavior.
options.DontFragment = true;

//Create a buffer of 32 bytes of data to be transmitted.
string data = "";
PingReply reply = pingSender.Send(data);
if (reply.Status == IPStatus.Success)
Console.WriteLine("Address: {0}", reply.Address.ToString());
Console.WriteLine("RoundTrip time: {0}", reply.RoundtripTime);
Console.WriteLine("Time to live: {0}", reply.Options.Ttl);
Console.WriteLine("Don't fragment: {0}", reply.Options.DontFragment);
Console.WriteLine("Buffer size: {0}", reply.Buffer.Length);
pablo ramos1 20-Sep-11 13:51pm    
Every time i have to create 10 Threads to execute this Methode, after i kill their and create a new 10 Threads to do the same work
Herman<T>.Instance 20-Sep-11 17:40pm    
is this 'restart' part of TimerEvent?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900