System.IndexOutOfRangeException: Index was outside the bounds of the array.
exception occurs when I searching text in multiple files at the same time but when I execute one task at a time there are no exceptions.
These files are throwing an exception:
pdf_files.zip (6.1 MB)
Aspose.PDF 20.8.0 version, .NETStandard 2.1
Code snippet:
static void Main(string[] args)
{
License license = new License();
license.SetLicense("C:\\path\\to\\license");
var pdfFiles = Directory.GetFiles("C:\\directory\\to\\the\\files");
var documents = new List<Document>();
foreach (var pdfPath in pdfFiles)
{
Console.WriteLine($"Create document {pdfPath}");
documents.Add(new Document(pdfPath));
}
// int maxConcurrentTasks = 1; //no exception
int maxConcurrentTasks = 10; //exception
Console.WriteLine("Start searching");
Parallel.ForEach(documents, new ParallelOptions{ MaxDegreeOfParallelism = maxConcurrentTasks },document => scan(document));
}
static void scan(Document doc)
{
try
{
Thread.Sleep(5000);
foreach (Page actualPage in doc.Pages)
{
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("dummy_regex")
{
TextSearchOptions = { IsRegularExpressionUsed = true }
};
actualPage.Accept(textFragmentAbsorber);
}
}
catch (Exception e)
{
Console.WriteLine($"Exception occured {doc.FileName}");
Console.WriteLine(e);
}
}
Thanks,
Gabor