I have a .NET application that uses Aspose libraries to convert PDF files to TIF files, and it uses Parallel.Foreach to perform these conversions simultaneously in multiple threads. In each thread, I create a new Resolution object, new TIffSettings object, and new TiffDevice object:
[code]
private TiffDevice getTiffConverter()
{
Resolution resolution = new Resolution(300);
var tiffSettings = new TiffSettings()
{
Compression = CompressionType.LZW,
Depth = ColorDepth.Format8bpp,
Shape = ShapeType.None,
SkipBlankPages = false
};
return new TiffDevice(resolution, tiffSettings);
}
[end code]
A new Pdf.Document object is created in each thread and TiffDevice.Process is called, where fileFullName and destinationFileFullName are strings:
[code]
using (var pdfToConvert = new Document(fileFullName))
{
var tiffConverter = getTiffConverter();
tiffConverter.Process(pdfToConvert, destinationFileFullName);
}
[end code]
When I run this with only 1 thread, it works fine, but if I run this in 10 simultaneous threads, then about 10% of the files will encounter the following exception:
[exception]
Message: Arithmetic operation resulted in an overflow.
Target Site: Int32 ToInt32()
Stack Trace: at System.IntPtr.ToInt32()
at ****.Get8BppImage(Bitmap )
at ****.***(Bitmap , PixelFormat )
at ****.**(Bitmap , Int32 , Int32 )
at ****.AddImage(Bitmap )
at Aspose.Pdf.Devices.TiffDevice.Process(Document document, Int32 fromPage, Int32 toPage, Stream output)
at Aspose.Pdf.Devices.DocumentDevice.Process(Document document, Stream output)
at Aspose.Pdf.Devices.DocumentDevice.Process(Document document, String outputFileName)
...
[end exception]
So the exception is happening underneath Aspose code, and I've also determined that PDF files where the exception occurs once can convert succesfully in repeated trials, so it doesn't seem to be related to specific PDF files. And even though it's around 10% of the files and 10 threads, the errors have come from any of the threads, not just one particular thread out of 10. I'm using Aspose.Pdf.dll version 10.5.0.0. Is this a bug? Is there anything I can do to work around it while still using multiple threads?