Here is the code and the excel I am using to test. When I replace CalculateFormula line with Thread.Sleep(500), the code works perfectly. As soon as I put back CalculateFormula, memory grows to couple of Gigs and eventually throws OutofMemory Exception.
using System;
using System.Threading;
using Aspose.Cells;
namespace FeeTester
{
class Program
{
static void Main()
{
const int threadCount = 25;
var threads = new Thread[threadCount];
for (int i = 0; i < threadCount; i++)
{
threads[i] = new Thread(Call);
threads[i].Start(i);
Console.WriteLine("Started Thread " + (i + 1));
}
for (int i = 0; i < threadCount; i++)
threads[i].Join();
Console.WriteLine("Waiting for all Threads to finish");
Console.ReadLine();
}
static void Call(object input)
{
var wb = new Workbook(@"KY_Structure_v1.xlsx");
for(int i = 0; i < 1000; i++)
{
int index = wb.Worksheets.AddCopy("INPUT_OUTPUT");
Worksheet ws = wb.Worksheets[index];
ws.CalculateFormula(false, false, null); //Thread.Sleep(500);
wb.Worksheets.RemoveAt(index);
}
Console.WriteLine(string.Format("Thread - {0} is done", input));
}
}
}