110,537
社区成员
发帖
与我相关
我的任务
分享
//threadNum = 1000
//根据上传线程数计算分页上传页数和单页上传数据数
int forNum = threadNum;
double totalRows = dss.Tables[0].Rows.Count;
double perUploadDataRows = Math.Floor(Convert.ToDouble(totalRows / forNum));
int otherDataRows = (int)totalRows % forNum;
Console.WriteLine("每页上传数[" + perUploadDataRows + "]");
for (int i = 0; i < forNum; i++)
{
if (i == 0)
startIndex[i] = 0;
else
startIndex[i] = (int)perUploadDataRows * i;
if(i == forNum - 1)
endIndex[i] = (int)perUploadDataRows * (i + 1) + otherDataRows;
else
endIndex[i] = (int)perUploadDataRows * (i + 1);
Console.WriteLine(i + "号线程搜索区间:[" + startIndex[i] + "-" + endIndex[i] + "]");
//启动病案查询线程线程
th_PerThreadUpload[i] = new Thread(PerThreadUpload);
th_PerThreadUpload[i].Start(i);//开始线程,代入参数
}
//如果不需要等待所有线程执行完成就可以继续后面的流程
Task.Run(() => Parallel.For(0, forNum, i => PerThreadUpload(i)));
//如果需要等待所有线程执行完成才可以继续后面的流程
Parallel.For(0, forNum, i => {PerThreadUpload(i));