Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi thread worker thread status

I create my threads as

 for (int i = 0; i < threadCount; i++)
 {
     Searcher src = new Searcher(i, this);

     threads[i] = new Thread(new ThreadStart(src.getIpRange));
     threads[i].Name = string.Format(i.ToString());
  }

  foreach (Thread t in threads)
  {
     t.Start();
  }

with threadCount(= 100, 150, 255 etc...) but I can't learn how many threads working. on execute time.

and I want to control when all threads finishes their job. and give me a message like "All threads are dead, jobs completed..." like backgroundWorker's RunWorkerCompleted event

like image 832
Rapunzo Avatar asked Mar 03 '26 20:03

Rapunzo


1 Answers

Determining when all the threads are finished is simple.

for (int i = 0; i < threadCount; i++)
{
    threads[i].Join();
}

Console.WriteLine("All threads are done!");

Can you elaborate on your other requirements?

like image 185
Winston Smith Avatar answered Mar 05 '26 11:03

Winston Smith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!