Control hangs when calling FlushDocument within OnEvent

PDF-XChange Viewer SDK for Developer's
(ActiveX and Simple DLL Versions)

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

asadatec
User
Posts: 5
Joined: Tue Nov 10, 2009 10:20 am

Control hangs when calling FlushDocument within OnEvent

Post by asadatec »

Hello,
in some cases the control hangs when you call Flushdocument (and maybe other commands) within the OnEvent handler. This happened when I tried to catch the keypress of CTRL+S and call the save-method (and there of course the FlushDocument).

Code: Select all

    Private Sub PDFViewerEvent(ByVal sender As Object, ByVal e As AxPDFXCviewAxLib._IPDFXCviewEvents_OnEventEvent) Handles _PDFViewer.OnEvent
            If e.name.ToLower.Contains("notifications.keyboard") Then
                Dim Code As Integer
                Try
                    _PDFViewer.GetProperty("Notifications.Keyboard.Code", Code, 0)
                    'STRG+S gedrückt
                    If Code = 19 Then
                        RaiseEvent CtrlSPressed()
                    End If
                Catch
                End Try
            End If
The event is catched by the window and it calls the save method of my object again. Calling the save method from the window when pressed a button does work! The problem seems to be the call from OnEvent.

This code can kill the control too:

Code: Select all

    Private Sub PDFViewerEvent(ByVal sender As Object, ByVal e As AxPDFXCviewAxLib._IPDFXCviewEvents_OnEventEvent) Handles _PDFViewer.OnEvent
            _PDFViewer.FlushDocument(0)
It looks like an endless loop, but only within your control, the event is not fired all the time.

Control Version 2.5.0199

Sebastian
Thank You,
Sebastian
User avatar
Vasyl - PDF-XChange
Site Admin
Posts: 2445
Joined: Thu Jun 30, 2005 4:11 pm

Re: Control hangs when calling FlushDocument within OnEvent

Post by Vasyl - PDF-XChange »

Hi, Sebastian.

Code: Select all

Private Sub PDFViewerEvent(ByVal sender As Object, ByVal e As AxPDFXCviewAxLib._IPDFXCviewEvents_OnEventEvent) Handles _PDFViewer.OnEvent
            _PDFViewer.FlushDocument(0)
1. Do not call the 'FlushDocument' for EACH event from pdf-viewer.
2. Try to call it (and other commands, excepting GetProperty/SetProperty) with special flag PXCVA_Sync:

Code: Select all

PDFViewerEvent(...)
{
   if (<SAVE_DOC_CONDITION>)
   {
       _PDFViewer.FlushDocument(0, PXCVA_Sync);
       _PDFViewer.SaveDocument(0, NULL, PXCVA_Sync); // Note: the SaveDocument() already calls the FlushDocument() before
       ...
   }
}
3. BUT the best solution is:

Code: Select all

PDFViewerEvent(..)
{
   if (<SAVE_DOC_CONDITION>)
   {
       yourForm.PostMessage(MSG_ASYNCSAVEDOC);
   }
}
--------------
yourForm
{
     OnAsyncSaveDoc(...)
     {
          _PDFViewer.SaveDocument(0, NULL, 0);
          ...
     }
}
HTH.
PDF-XChange Co. LTD (Project Developer)

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
asadatec
User
Posts: 5
Joined: Tue Nov 10, 2009 10:20 am

Re: Control hangs when calling FlushDocument within OnEvent

Post by asadatec »

Of course I am not calling FlushDocument every time in each Event Handler!

And thanks, it works. And thanks to Stefan for the good email support.
Thank You,
Sebastian
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19885
Joined: Mon Jan 12, 2009 8:07 am

Re: Control hangs when calling FlushDocument within OnEvent

Post by Stefan - PDF-XChange »

Pleasure we could help Sebastian!

And glad to hear that Vasyl's suggestion works properly!

Best,
Stefan