I am trying to create a thumbnail image of pdf in Monotouch but the app crashes sometimes and throws below error.
Stacktrace:
at MonoTouch.CoreFoundation.CFString.Dispose () [0x00000] in /Developer/MonoTouch/Source/monotouch/src/shared/CoreFoundation/CFString.cs:131
at MonoTouch.CoreFoundation.CFUrl.FromFile (string) [0x00048] in /Developer/MonoTouch/Source/monotouch/src/shared/CoreFoundation/CFUrl.cs:79 at MonoTouch.CoreGraphics.CGPDFDocument.FromFile (string) [0x00000] in /Developer/MonoTouch/Source/monotouch/src/shared/CoreGraphics/CGPDFDocument.cs:98
Below is my code to generate the thumbnail image and they're inside of BackgroundWorker thread. The weird thing is that it does not happen always. Does anybody have idea why this is happening? Thanks in advance.
try
{
CGPDFDocument pdfDoc = CGPDFDocument.FromFile(url);
if (pdfDoc != null)
{
CGPDFPage pdfPage = pdfDoc.GetPage(1);
if (pdfPage != null)
{
UIImage image = PDFConverter.TransformToImage(pdfPage, this.Frame.Width);
}
}
}
catch (Exception ex)
{
Console.WriteLine("BookmarkView - BookmarkView: {0}", ex.ToString());
}