问题
I have Excel file has 4 sheets, all sheets have huge number of records around 144564 record.
In my code, fill_data method will call 4 methods, each method read one sheet. the normal time it takes now is 7.02 minutes.
fill_data ()
{
Excel.Application ExcelApplication;
Excel.Workbooks ExcelWorkbooks;
Excel.Workbook ExcelWorkbook1;
ExcelApplication = new Excel.Application(); /// ApplicationClass()
ExcelWorkbooks = ExcelApplication.Workbooks;
try
{
ExcelWorkbook1 = ExcelApplication.Workbooks.Open(fileName1, 0, true, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true);
}
catch
{
return;
}
active1 = ExcelWorkbook1.Worksheets.get_Item(1); // students list
active2 = ExcelWorkbook2.Worksheets.get_Item(2);
active3 = ExcelWorkbook3.Worksheets.get_Item(3);
active4 = ExcelWorkbook4.Worksheets.get_Item(4);
fill_students();
fill_instructors();
fill_exams();
fill_rooms();
}
public static void fill_students(){
Excel.Worksheet active = active1;
//Read all Cells at Sheet
}
I try to use the Parallel feature to make the 4 methods run in parallel, instead of explicitly call methods I use invoke at Parallel class. As the following:
fill_data ()
{
.....
Parallel.Invoke(
() => fill_students(),
() => fill_instructors(),
() => fill_exams(),
() => fill_rooms()
);
}
There is no enhancement on the executing time! it was 7.12 minutes! So what is going wrong? how to minimize this time?
来源:https://stackoverflow.com/questions/39555945/parallelize-minimize-time-reading-number-of-sheets-from-excel-file