问题描述
Thread[]thread=newThread[length];for(inti=0;i<length;i++){thread[i]=newThread(newThreadStart(Bound));thread[i].Name=i.ToString();thread[i].Start();}下面的线程一定要join一下,要不就不执行了,到底是什么原因for(inti=0;i<length;i++){thread[i].Join();}publicvoidBound(){try{for(inti=0;i<list.Count;i++){lock(temp){if(temp.Split(',').Length==list.Count){break;}if(temp.IndexOf(list[i].ToString())==-1){TextBox1.Text=TextBox1.Text+"------------------------n"+GetContent(list[i].ToString()).Substring(0,300);temp=temp+list[i].ToString()+",";}}}Response.Write(Thread.CurrentThread.Name);Thread.Sleep(2);Thread.CurrentThread.Abort();}catch(Exceptionex){if(Interlocked.Increment(refthreadCounter)==length){end=DateTime.Now;ts=end-start;Label1.Text="耗时"+ts.Seconds+"秒";}}
时间: 2024-10-25 07:04:33