Reputation: 132
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.
Upvotes: 1
Views: 2653
Reputation: 132
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.
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
Upvotes: 1