.Net 7 WinForms - process hangs after closing the app  SOLVED

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
zarkogajic
User
Posts: 1372
Joined: Thu Sep 05, 2019 12:35 pm

.Net 7 WinForms - process hangs after closing the app

Post by zarkogajic »

Hi Support,

Can you shed some light on the following:

Attached are two super simple same WinForms applications using AxPXV_Control:

"DotNetFrameworkWinFormsSimple.zip" using ".NET Framework 4.8.9181.0"
DotNetFrameworkWinFormsSimple.zip
(10.64 KiB) Downloaded 89 times
"DotNetWinFormsSimple.zip" using ".NET 7.0.12".
DotNetWinFormsSimple.zip
(5.48 KiB) Downloaded 90 times

As you can see in (main) Form1's constructor I'm manually calling PXV_Inst.Init() and PXV_Inst.Shutdown() in both apps.

In the case of ".Net 7.x" - after closing the main form - the process is kept in memory and never actually terminates.

The same happens even if I do *not* manually call Init()/Shutdown() - but let the AxPXV_Control do the Init/Shutdown thingie.

In case of ".NET Framework 4.x" - all works as expected - the app closes and the process is also terminated.

The following is a kind of a workaround, for .Net 7, but does not smell nice :)

Code: Select all

// Workaround for process hang issue detected on PDFX version 10.0.1.380 / .Net 7
while (PxvInst.State != (int)PXV_InstStateFlags.PXV_InstState_ShutDown)
{
  PxvInst.Shutdown();
}
Is this a bug or expected or ?

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

Re: .Net 7 WinForms - process hangs after closing the app

Post by Vasyl-Tracker Dev Team »

Hi Zarko.

We investigated it and found that under Net7 our ActiveX control doesn't receive the destroy-event from the system when the system destroys the control's window. Which is quite strange and critical for the control because it finalizes itself at this event. In the new upcoming build we added the workaround for this case, and it seems it works better now. Also, the second part of the fix needs to be done in your code too. You need to release (set to *null*) all used references to sdk-objects before cleaning the GC. I.e., instead of this:

Code: Select all

private readonly PXV_Inst pxvInst = new();

public Form1()
{
      pxvInst.Init();
      ....
}

private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
      pxvInst.Shutdown(); 
      GC.Collect();
      GC.WaitForPendingFinalizers();
}
is better to use this way:

Code: Select all

private PXV_Inst pxvInst;

public Form1()
{
      pxvInst = new();
      pxvInst.Init();
      ....
}

private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
      pxvInst.Shutdown(); 
      pxvInst = null; // important(!) to do it here
      GC.Collect();
      GC.WaitForPendingFinalizers();
}
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.
zarkogajic
User
Posts: 1372
Joined: Thu Sep 05, 2019 12:35 pm

Re: .Net 7 WinForms - process hangs after closing the app  SOLVED

Post by zarkogajic »

Hi Vasyl,

Great, thanks!

ž
User avatar
Dimitar - Tracker Supp
Site Admin
Posts: 1797
Joined: Mon Jan 15, 2018 9:01 am

.Net 7 WinForms - process hangs after closing the app

Post by Dimitar - Tracker Supp »

:)
Post Reply