VB.Net / Acrobat - Acrobat hangs after user manually exits program

一笑奈何 提交于 2019-12-11 10:25:49

问题


I'm currently having an issue with VB.Net and Adobe Acrobat. The issue comes from exiting Acrobat but the Windows Taskbar still states that there is an Acrobat.exe process open. I have tried using Marshal.ReleaseComObject(), but it still hangs there. I do not want to have to rely on the "End Process" option on the Task bar in order to remove it.

Below is a snippet of the code that I am try to using:

Try
   'Tries To Close Acrobat Application
        acrobatApp.Exit()
        System.Runtime.InteropServices.Marshal.ReleaseComObject(javaScriptObj)
        javaScriptObj = Nothing
        System.Runtime.InteropServices.Marshal.ReleaseComObject(acroPDDoc)
        acroPDDoc = Nothing
        System.Runtime.InteropServices.Marshal.ReleaseComObject(acrobatAVDoc)
        acrobatAVDoc = Nothing
        System.Runtime.InteropServices.Marshal.ReleaseComObject(acrobatApp)
        acrobatApp = Nothing

   'Below is a snippet of code that I found for garbage collecting, but it did not work
        'GC.Collect()
        'GC.WaitForPendingFinalizers()

    Catch ex As Exception
        'Acrobat Could Be Closed Already
    End Try

Although I am not sure if this could be a problem - I run a javascript saveAs script on the Acrobat side in order to make a copy of the file. This also could be a reason why it is hanging, but I ruled it out based on basic knowledge of saving files and exiting from other Acrobat/Microsoft Programs.

Any Help would be beneficial! Thanks!

Edit: -I forgot to mention that Acrobat only closes when my application ends. (Currently) I am trying to make it consider the case if a user manually closes the Acrobat application.


回答1:


I figure I would not be the only one having trouble with this, so I came up with a "dirty answer" to this question. Although it is not the most conventional way of answering this question, it can be done through this process.

  1. Get total opened acrobat files.
  2. Loop through the entire opened Acrobat files - and store the file names into a temp data structure (arrayList, array, etc)
  3. run the "acrobatApp.CloseAllDocs()", "acrobatApp.Exit()", and a function that kills the entire Acrobat Process.
  4. Re-Open the documents from the VB side - use the links that were stored inside the data structure.
  5. Display Acrobat.

    If acrobatApp IsNot Nothing AndAlso acrobatApp.GetNumAVDocs > 0 Then
            Dim docs(acrobatApp.GetNumAVDocs) As String
    
            'Saving And Formatting Names Of Opened Documents
            For i = 0 To acrobatApp.GetNumAVDocs - 1
                acrobatAVDoc = acrobatApp.GetAVDoc(i)
                acroPDDoc = acrobatAVDoc.GetPDDoc
                javaScriptObj = acroPDDoc.GetJSObject
                docs(i) = javaScriptObj.path().ToString.Replace("/", "\").Substring(1)
                position = docs(i).IndexOf("\")
                docs(i) = docs(i).Substring(0, position) + ":\" + docs(i).Substring(position + 1)
            Next
    
            'Closing And Killing Acrobat Application
            acrobatApp.CloseAllDocs()
            KillAcrobat()
    
            'Creating New Instance Of Acrobat
            acrobatApp = CreateObject("AcroExch.App")
    
            'Opening All Previously Opened Documents
            For i = 0 To docs.Length - 1
                acrobatAVDoc = CreateObject("AcroExch.AVDoc")
                acrobatAVDoc.Open(docs(i), Path.GetFileName(docs(i)))
            Next
    
            'Displaying The Application
            acrobatApp.Show()
    
        End If
    


来源:https://stackoverflow.com/questions/10884104/vb-net-acrobat-acrobat-hangs-after-user-manually-exits-program

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!