本文介绍了递归创建线程后,如何判断它们何时完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 在我的Windows C#app中,我创建了一个线程,将主代码块 从GUI中分离出来,递归地对所有目录进行排序 从给定开始点,并且每次找到* .html时文件, 它启动一个新线程去处理该文件。由于每个 个别线程都不必触及另一个''s档,这个工作 罚款。 什么我需要知道所有这些线程何时完成。 理论上很多线程都可以被提示,我遇到了麻烦 搞清楚如何存储一个参考列表,所以我可以检查 他们的.IsAlive状态。 任何人都可以给我任何指示吗?In my windows C# app, I create a thread to separate the main code blockfrom the GUI, which recursively sorts through all the directoriesstarting from a given point, and every time it finds a "*.html" file,it starts a new thread to go to work on that file. Since eachindividual thread doesn''t have to touch another''s file, this worksfine.What I need to know is when all of these threads are finished.Theoretically a lot of threads could be cued, and I''m having troublefiguring out how to store a list of references to them so I can checktheir ".IsAlive" state.Can anyone give me any pointers?推荐答案 好​​吧,你可以将线程引用添加到列表中,就像你要添加的一样任何 其他参考。您只需要访问一个公共列表。然而,不是使用IsAlive属性,我会在 中的每个线程上调用Join,等待它完成。 (你可以在一个额外的 线程中执行此操作,然后告诉UI线程,一切都已完成,如果你想要 。)如果你只有一个但是,这可能不是必需的 - 你可能会发现将应用程序分成可能是 UI线程,搜索和线程和处理线程线程将 自然使生活更简单。 - Jon Skeet - < sk *** @ pobox.com> ; http://www.pobox.com/~skeet 博客: http://www.msmvps.com/jon.skeet 如果回复该组,请不要给我发邮件Well, you can add Thread references to a list just like you''d add anyother reference. You just need access to a common list. Rather thanusing the IsAlive property, however, I''d call Join on each thread inturn to wait until it''s finished. (You could do this in a single extrathread which then "told" the UI thread that everything had finished, ifyou want.) If you only have a couple of threads, however, this may notbe necessary - you may well find that separating the app into maybe theUI thread, the "searching" thread and the "processing" thread wouldnaturally make life simpler.--Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeetIf replying to the group, please do not mail me too 这篇关于递归创建线程后,如何判断它们何时完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-28 11:14