This issue affects both my VB.NET and C# Winform applications. When closing Form containing Adobe PDF Viewer conreol, the Form takex some 10 seconds to close. I tracked the issue down to Dispose method. Normally, in C# all it takes it so steal focus from Adobe PDF Control by adding lines to FormClosing event handler but in VB.NET, even if I steal focus, it still takes way too long for the Form to close. I tried to explicitly dispose the control and Implicitly - by disposing the containing Form. I tried empty string in LoadFile() method. I tried new reference to new interop library. Nothing works.
Also, if you would suggest a different API/library to replace AxAcroPDFlib I'd love to read what you use.
Acrobat PDF viewer control takes time to dispose
1k Views Asked by ArtK At
1
I now have a solution. Early testing is promising. In short, add
Controls.Remove(yourPdfViewerControl)toFormClosingevent handler. Of course this will offer instant alleviation of the problem but may cause memory leak. After you have removed the control fromContaineryou could assugnnullto its memory address and hope that memory manager will do its job.So in order to prevent the leak, I created a class holding one memory space for
PdfViewercontrol. If aFormneeds a viewer, it requests it from an object that is accessible from any form to prevent memory leaks. To avoidDisposemethod invocation whenFormcloses, make sure you remove thisControlfromControlscontainer. I can provide sample code if needed.