AutoResetEvent[] autoEvents = InitAutoResetEvent();
List lst = new List();
//得到处理数据 集
DataSet ds = GetBeforeJP();
//验证数据是否存在(null)
if (!DataHelper.VerifyDataSet(ds))
{
Thread.Sleep(100);
continue; //如果检测DataSet可行,则继续
}
int iCount = ds.Tables[0].Rows.Count; //获取要处理的数据行数
int iBlock = (int)Math.Ceiling((double)iCount / MaxThread);//根据行数,线程数设定每个线程要处理的数据量
for (int i = 0; i < MaxThread; i++) //像线程池加入执行队列
{
ThreadPool.QueueUserWorkItem(data =>
{
int iIndex = (int)data;//线程序号0->MaxThread
DataRowCollection rows = ds.Tables[0].Rows;
for (int j = 0; j < iBlock; j++)
{
try
{
if (iIndex * iBlock + j >= iCount)//避免最后一个线程索引越界
break