判断所有子线程执行完,教我下,谢谢
本帖最后由 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();
}
using (fastCSharp.threading.task task = new fastCSharp.threading.task(10, true))
{
for (int i = 0; i < 10; i++)
{
task.Add(() =>
{
//do something
});
}
}
Console.WriteLine("线程执行完毕");
static void Main()
{
PExecuteMethod();
Console.ReadLine();
}
private static void PExecuteMethod()
{
Parallel.For(0, 10, (i) =>
{
//do your job here
DealWithHtmlUrl(i);
});
Console.WriteLine("任务执行完毕.");
TodoTheLastMethod();
}
private static void TodoTheLastMethod()
{
//The Last Method todo here
Console.WriteLine("The Last Method todo here");
}
private static void DealWithHtmlUrl(int i)
{
//throw new NotImplementedException();
//todo: 针对第i个url的处理
Console.WriteLine("针对第{0}个url的处理", i);
}