I've got a form with two buttons on it. Clicking on the buttons displays an htm document in the default viewer.

What I want to happen is for a new viewer to be launched on the first button press and then the same viewer instance to be used for all subsequent button presses.

I've got the following code, but it doesn't reuse the viewer that is launched, it just starts up a new one.

Any ideas?

VB Code:
  1. Dim WithEvents proc As New Process()
  2.     Dim gblnProcessRunning As Boolean = False
  3.  
  4.     Private Sub LoadDocument(ByVal str As String)
  5.  
  6.         proc.EnableRaisingEvents = True
  7.  
  8.         If gblnProcessRunning Then
  9.             proc.Close()
  10.             proc.StartInfo.FileName = str
  11.             proc.Start()
  12.         Else
  13.             Try
  14.                 With proc.StartInfo
  15.                     .FileName = str
  16.                     .UseShellExecute = True
  17.                     .ErrorDialog = True
  18.                     .ErrorDialogParentHandle = Me.Handle
  19.                 End With
  20.                 proc.Start()
  21.                 gblnProcessRunning = True
  22.             Catch ex As Exception
  23.                 Debug.WriteLine(ex.Message)
  24.             End Try
  25.         End If
  26.  
  27.     End Sub
  28.  
  29.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  30.         LoadDocument("d:\tspcd\mx\801b.htm")
  31.     End Sub
  32.  
  33.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  34.         LoadDocument("d:\tspcd\mx\snm800.htm")
  35.     End Sub
  36.  
  37.     Private Sub proc_Exited(ByVal sender As Object, ByVal e As System.EventArgs) Handles proc.Exited
  38.         gblnProcessRunning = False
  39.     End Sub