Rank: Newbie
Groups: Registered
Joined: 1/20/2016(UTC) Posts: 7
|
I'm getting a System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt... Sometimes -- Patagames.Pdf.Pdfium.FPDF_CreateNewDocument_native() or -- Patagames.Pdf.Pdfium.FPDF_CloseDocument_native(IntPtr document) I'm running a parallel.foreach (15 threads), each task gets a unique "infile". The error doesn't occur for each thread, but eventually does throw. Code:
PdfCommon.Initialize();
using (var sourceDoc = Patagames.Pdf.Net.PdfDocument.Load(infile)
{
for (var i = 1; i <= sourceDoc.Pages.Count; i++)
{
string tmppagepdf = Guid.NewGuid().ToString();
using (FileStream fs = new FileStream(@"e:\workingfolder\" + tmppagepdf, FileMode.Create))
{
using (var doc = Patagames.Pdf.Net.PdfDocument.CreateNew()) // <-- EXCEPTION SOMETIMES
{
doc.Pages.ImportPages(sourceDoc, i.ToString(), 0); // <-- EXCEPTION SOMETIMES
doc.Save(fs, SaveFlags.Incremental);
}
}
//do stuff on the file for this page
// ...
File.Delete(@"e:\workingfolder\" + tmppagepdf);
}
}
PdfCommon.Release();
Edited by user Thursday, January 21, 2016 4:41:52 PM(UTC)
| Reason: Not specified
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 1/5/2016(UTC) Posts: 1,109
Thanks: 7 times Was thanked: 130 time(s) in 127 post(s)
|
you must call the initialize / release methods once in proccess. Otherwise, you are having the situation when one thread already release the library, but the other thread is still working with the library. Edited by user Thursday, January 21, 2016 5:49:23 PM(UTC)
| Reason: Not specified
|
|
|
|
Rank: Newbie
Groups: Registered
Joined: 1/20/2016(UTC) Posts: 7
|
that seems to fix it. So in an asp.net app, I would call initialize() once in Application_Start?
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 1/5/2016(UTC) Posts: 1,109
Thanks: 7 times Was thanked: 130 time(s) in 127 post(s)
|
Yes. And don't call Release().
|
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.
Important Information:
The Patagames Software Support Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close