gpt4 book ai didi

c# - 多线程工作线程状态

转载 作者:行者123 更新时间:2023-11-30 15:10:05 25 4
gpt4 key购买 nike

我创建我的主题为

 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...) 但我不知道有多少线程在工作。关于执行时间。

我想控制所有线程何时完成它们的工作。给我一条消息,比如“所有线程都死了,作业完成了……”比如backgroundWorker的RunWorkerCompleted事件

最佳答案

确定所有线程何时完成很简单。

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

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

您能否详细说明您的其他要求?

关于c# - 多线程工作线程状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3583979/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com