I have reproduced the issue using the FullDemo project shipped with the SDK. My current version is 2.5 (build 194).
Gut the b_OpenDoc_Click method and replace it with what is shown below. The main problem occurs when the viewer is stressed by being told to open, save, close a document repeatedly. In the loop below, I typically blow up on the first iteration when DoEvents is commented out or the second iteration when DoEvents is left in. Two different bugs depending upon DoEvents being present.
The comments in the code describe the problem more. I have attached the PDF for your tests if you wish to use it.
Code: Select all
private void b_OpenDoc_Click(object sender, EventArgs e)
{
try
{
object dataIn = null;
object dataOut = null;
for (int i = 0; i < 10; i++)
{
// This document has "On Load" javascript that will rotate the page thereby causing it
// to go "dirty".
dataIn = @"C:\Temp\2.pdf";
System.Diagnostics.Debug.WriteLine("TEST: Loading the document");
axCoPDFXCview1.DoVerb(null, "OpenDocument", dataIn, out dataOut, (int)PXCVA_Flags.PXCVA_NoUI);
int activeDocumentId = Convert.ToInt32(dataOut);
// NOTES:
// The Save and Close operations are where things get foo-bar'ed. Two problems exist here.
//
// 1. Without the Application.DoEvents() below, the viewer will "freeze" while
// executing the Save operation. You will be able to Break All threads in
// the debugger and see that the main thread is sitting on the DoVerb for
// SaveDocument.
//
// 2. Once you add the DoEvents below, you will release some of the contention
// between the out of process viewer and the UI host. Now the code will
// burp in the Close operation and show the "Confirm Document Save" dialog asking
// "Do you want to save changes before closing?". Please note that I have
// indicated NoUI in my flags to Open, Save, and Close.
//
// This bug is even worse than just showing the UI. Since I'm in a loop, the
// thread in *this* process will continue to execute. Pretty soon I will have
// several dialogs asking me if I want to save or not when using the debugger
// to step through the code. When I "just let the debugger run", I will only
// get one dialog. If I press NO, then life will continue. If I press YES,
// well, life goes bad very quickly as the out of process viewer tries to save
// a document that is no longer there. The viewer ends up dying in the end.
//
Application.DoEvents();
System.Diagnostics.Debug.WriteLine("TEST: Saving the document");
dataIn = new object[] { activeDocumentId, @"C:\Temp\2.pdf.saved" };
axCoPDFXCview1.DoVerb(null, "SaveDocument", dataIn, out dataOut, (int)PXCVA_Flags.PXCVA_NoUI);
System.Diagnostics.Debug.WriteLine("TEST: Closing the document");
axCoPDFXCview1.DoVerb(null, "CloseDocument", activeDocumentId, out dataOut, (int)PXCVA_Flags.PXCVA_NoUI);
}
}
catch (Exception exception)
{
return;
}
}