I am accessing XLSX Files and summing up the [FileSize]
Values of a Column, it contains more than 100k rows.
I wanted to use OLEDB
in combination with multitasks. After that I want the tasks to return an integer/float value so I can calculate the percentage of each XLSX file compared to the total file size.
So far I have this code:
foreach (string subdir in alldir)
{
Task<int> iSize = Task<int>.Factory.StartNew(() =>
{
int result = 0;
using (OleDbConnection olecnn = new OleDbConnection(GetConnectionString(subdir)))
{
try
{
olecnn.Open();
using (OleDbCommand sumcmd = new OleDbCommand("SELECT SUM([File Size]) FROM [FileInfos$]"))
{
sumcmd.Connection = olecnn;
result = (int)sumcmd.ExecuteScalar();
//BarChart.Series["Memory Usage"].Points.AddXY(Path.GetFileName(subdir), result);
return result;
}
olecnn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString()); return result;
}
}
}).ContinueWith(cnt => cnt.Dispose());
}
There seems to be an syntax error
Cannot implicitly convert type '
System.Threading.Tasks.Tasks
' to 'System.Threading.Tasks.Task<int>
'. An explicit conversion exists (are you missing a cast)?
I read the docs but can't figure out how to get the result
as integer/float, so I can proceed with this value.