PXV_Inst System.AccessViolationException

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
baumunk
User
Posts: 38
Joined: Fri Nov 13, 2020 8:47 am

PXV_Inst System.AccessViolationException

Post by baumunk »

Is it allowed to create and release inctance multiple times in one application in PXV_Inst?

Code: Select all

Inst = new PDFXEdit.PXV_Inst();
Inst.Init(null, licKeyEdit, (IString)null, (IString)null, (IString)null);
....
// Convert PDF
...
Marshal.FinalReleaseComObject(Inst);
Inst = null;
For multiple customers who use PDF/A conversion intensively,
sporadically System.AccessViolationException occurs when calling PXV_Inst.Init

How can I avoid this?

I have only guess that instance of PXV_Inst can be created only once per application.

With kind regards
Ernest Baumunk
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: PXV_Inst System.AccessViolationException

Post by zarkogajic »

Hi Ernest,

Are you calling https://sdkhelp.pdf-xchange.com/view/PXV:IPXV_Inst_Shutdown ?

Note (from SDK help page):

"It is also essential when all tasks are completed and use of the SDK is no longer required that you call IPXV_Inst::Shutdown to release all used resource and correctly close all working threads, etc. "

-žarko
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2352
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: PXV_Inst System.AccessViolationException

Post by Vasyl-Tracker Dev Team »

Good point, Zarko. Thanks for the help. And in detail:

Code: Select all

private void RunPDFX(....)
{
   Inst = new PDFXEdit.PXV_Inst();
   Inst.Init(...)

   // ... work with PDFX-API

   Inst.Shutdown();

   /////////////////////////////////////////////////////////////////////////////////////
   // Forced release of all COM-objects that may still be captured by Garbage Collector.
   // It is critical to release them before destroying Inst!
   /////////////////////////////////////////////////////////////////////////////////////

   GC.Collect();
   GC.WaitForPendingFinalizers();
   Inst = nullptr;
};

//////////////////////////////////////////////////////////////////////

for (...)
{
     RunPDFX(....); 
}
This code shoud work as well. But for sure - it's not effective to use Init/Shutdown too often. Ideally - just once per app lifetime.

Note: the PXV_Inst-object - is the true singleton. So if you try to create 2 different PXV_Inst-object at the same time - then technically you will get just two references to the same object instantiated at the first 'new' operator.

HTH.
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
baumunk
User
Posts: 38
Joined: Fri Nov 13, 2020 8:47 am

Re: PXV_Inst System.AccessViolationException

Post by baumunk »

You write:

"This code shoud work as well. But for sure - it's not effective to use Init/Shutdown too often. Ideally - just once per app lifetime."

But this means that converting parallel in two files (in different places) is not possible, correct?

Another question, if it is an instance, how does it behave if the instance is not accessed from the main thread?

Ernest Baumunk
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: PXV_Inst System.AccessViolationException

Post by zarkogajic »

Hi Ernest,

IPXC stuff (so Core stuff) is thread safe.

If you are using the "op.document.optimize" in a different thread - you will pass it an ipxc_document (for "Input") opened in that thread (IPXC_Inst::OpenDocumentFromFile) and all will run as expected.

-žarko
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17824
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: PXV_Inst System.AccessViolationException

Post by Tracker Supp-Stefan »

Hello zarkogajic,

Many thanks for your help here!

Kind regards,
Stefan
Post Reply