日期:2014-05-17  浏览次数:20391 次

判断所有子线程执行完,教我下,谢谢
本帖最后由 skynq 于 2013-02-25 11:19:20 编辑
主函数里面

static void Main(string[] args)
 {
     //我开了10个线程

    

      for (int i = 0; i < 10; i++)
                    {
                        Thread th = new Thread(() =>
                        {
                            for (int j = 0; j < htmlUrl.Count; j++)
                            {
                                getCount(htmlUrl[j]);
                                htmlUrl.Remove(htmlUrl[j]);   //清空

                            }
                        });

                        th.Start();
                    }
     

}

当然主函数里面还有其他调用的方法。我怎么判断这些子线程全部结束在执行我其他的方法。谢谢。

------解决方案--------------------
试试fastCSharp,供参考
            using (fastCSharp.threading.task task = new fastCSharp.threading.task(10, true))
            {
                for (int i = 0; i < 10; i++)
                {
                    task.Add(() =>
                    {
                        //do something
                    });
                }
         &nbs