I have a WinForm Application that reads data from an excel file using Spreadsheetlight, There is a method that reads the information then do some calculation an then I create a new excel File.
The problem is that this file has about 100,000 records and I have a label in the UI that I want to update every time I read an excel row, but the label just seems unresponsive;
public List<DataRow> GeExcelData(string filePath)
{
var myTable = new List<DataRow>();
int row = 0;
using (var input = new SLDocument(filePath))
{
SLWorksheetStatistics stats = input.GetWorksheetStatistics();
int iStartColumnIndex = stats.StartColumnIndex;
progressBar1.Minimum = 0;
progressBar1.Maximum = stats.EndRowIndex;
progressBar1.Step = 1;
for (row = stats.StartRowIndex + 1; row <= stats.EndRowIndex; ++row)
{
//Here is the label
lblStatus.Text = "Reading row " + row + " of " + stats.EndRowIndex;
var dataRowTmp = new DataRow()
{
name = input.GetCellValueAsString(row, iStartColumnIndex),
sku = input.GetCellValueAsString(row, iStartColumnIndex + 1),
value2 = input.GetCellValueAsString(row, iStartColumnIndex + 2),
value3 = input.GetCellValueAsString(row, iStartColumnIndex + 3)
};
progressBar1.PerformStep();
myTable.Add(dataRowTmp);
}
lblStatus.Text = "";
progressBar1.Value = 0;
}
return myTable;
}
Is there a way to update the UI efficiently, while doing some long-running tasks. Because is just a label I don't want to write some complex code. Also I have the progressBar1 that works fine.
Aucun commentaire:
Enregistrer un commentaire