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
984 Views Asked by ArtK At
1
I now have a solution. Early testing is promising. In short, add
Controls.Remove(yourPdfViewerControl)
toFormClosing
event handler. Of course this will offer instant alleviation of the problem but may cause memory leak. After you have removed the control fromContainer
you could assugnnull
to 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
PdfViewer
control. If aForm
needs a viewer, it requests it from an object that is accessible from any form to prevent memory leaks. To avoidDispose
method invocation whenForm
closes, make sure you remove thisControl
fromControls
container. I can provide sample code if needed.