How do I deal with a random error when using PDFViewCtrl to view PDF in my app?

Q: We encounter apparently random “UNKNOWN ERROR” when opening PDF in

Sometime, I open only 3 or 4 documents before the app crash, and
sometime I can open 40 doc before crash.

This is the code I use:

currentObjDoc = New PDFDoc(FilePath)

If (currentObjDoc IsNot Nothing) Then
       If currentObjDoc.InitSecurityHandler Then
       End If
End If

“Me” is PDFViewCtrl inerits object.

How can prevent this crash?

A: You need to get a reference to the old document, then set a new
document, then close the old document:

Dim olddoc As PDFDoc = _pdfview.GetDoc()
_pdfdoc = New PDFDoc(filename)
If Not (olddoc Is Nothing) Then
End If

For a concrete sample, please see PDFViewSimple sample project (http://

Btw. in this case there is no need to Lock()/Unlock() . This is needed
only is you are reading or modifying data in the document. In your
case it seems that you are only viewing and closing the document.