My codes as follow: Parallel.ForEach(listSheets, (xlWorkSheet1) => { // Excel.Worksheet xlWorkSheet1 = (Excel.Worksheet)excelbk.Worksheets["Sheet1"]; xlRange = (Excel.Range)xlWorkSheet1.Cells[xlWorkSheet1.Rows.Count, 1]; lock (xlRange) { // nRows = (long)xlRange.get_End(Excel.XlDirection.xlUp).Row; nRows = xlWorkSheet1.UsedRange.Cells.Rows.Count; xlRange = (Excel.Range)xlWorkSheet1.Rows["5:" + nRows, Type.Missing]; xlRange.Sort(xlRange.Columns[clnum1, Type.Missing], Excel.XlSortOrder.xlAscending, xlRange.Columns[clnum2, Type.Missing], Type.Missing, Excel.XlSortOrder.xlAscending, Type.Missing, Excel.XlSortOrder.xlAscending, Excel.XlYesNoGuess.xlNo, Type.Missing, Type.Missing, Excel.XlSortOrientation.xlSortColumns, Excel.XlSortMethod.xlStroke, Excel.XlSortDataOption.xlSortTextAsNumbers, Excel.XlSortDataOption.xlSortNormal, Excel.XlSortDataOption.xlSortNormal); [...]
read more