• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 210
  • Last Modified:

How to close Adobe Reader in code?

Hi,

I am using following code to print a pdf file from a windows app. The requirement is to close the acrobat view after the print. When I step through it, the

  MyProcess.CloseMainWindow()
will do the trick, but in real time, it dose not close the viewer.

Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
           Dim MyProcess As New System.Diagnostics.Process
           MyProcess.StartInfo.FileName = "c:\OrderForm.pdf"
           MyProcess.StartInfo.UseShellExecute = True
        MyProcess.StartInfo.Verb = "Print"
        MyProcess.Start()
        MyProcess.CloseMainWindow()
        Me.Close()
    End Sub
0
ommer
Asked:
ommer
  • 2
  • 2
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You may just need a small pause before closing the app...

        MyProcess.Start()
        System.Threading.Thread.Sleep(2000) ' two second pause
        MyProcess.CloseMainWindow()
        Me.Close()
0
 
ommerAuthor Commented:
Ok, I can see your point. But how to pause?

I have treid
 MyProcess.WaitForExit(10000)

The me.close has been delayed for 10 seconds, but the viewer did not close.

Thanks!
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
What do you mean "But how to pause?"...

I put it right there in the code example I gave:

        MyProcess.Start() ' start the process
        System.Threading.Thread.Sleep(10000) ' ten second pause
        MyProcess.CloseMainWindow() ' NOW try closing the main window?
        Me.Close() ' close the form

I suppose you can do it this way as well:

        MyProcess.Start()
        MyProcess.WaitForExit(10000)
        If Not MyProcess.HasExited Then
            MyProcess.CloseMainWindow()
        End If
        Me.Close()
0
 
ommerAuthor Commented:
That worked (the first one).
I thought you meant to insert a pause between CloseMainWindow() and me.close().
Thanks!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now