For those of you proficient in OpenXML, I'm using an Excel file (as resource) as a template for creating auto generated Excel files.
I copy the file to a MemoryStream, and after working with the template, it automatically downloads the file to the user's computer.
The Excel file is huge (around 40 sheets) and has a lot of information, mostly financial stuff. It takes some time to generate, and I would like this to be faster.
I've been thinking if it's possible to use my method to alter the excel sheet asynchronously. Instead of working one sheet at the time, do them all asynchronously. I've never used async so I'm going completely blind into this.
The method to work on the sheet doesn't return anything, it just changes the current used MemoryStream.
I've changed the method definition to
public async Task UpdateExcelUsingOpenXmlsdkAsync(string xmlStr, string fileName)
I've created a List of Tasks.
List<Task> sheetTasks = new List<Task>();
And I've wrapped my method calls inside
sheetTasks.Add(Task.Run(() => indice.TreatExcelSheetIndice(ds.Tables["ROW"], header.Tables["RELATORIO"], spreadSheet)));
This runs inside a foreach with a switch inside to treat each Sheet differently
After the foreach I have this
await Task.WhenAll(sheetTasks);
And then save the Spreadsheet. But it's not working. Does anyone know if this is possible?