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:
Dim WithEvents proc As New Process() Dim gblnProcessRunning As Boolean = False Private Sub LoadDocument(ByVal str As String) proc.EnableRaisingEvents = True If gblnProcessRunning Then proc.Close() proc.StartInfo.FileName = str proc.Start() Else Try With proc.StartInfo .FileName = str .UseShellExecute = True .ErrorDialog = True .ErrorDialogParentHandle = Me.Handle End With proc.Start() gblnProcessRunning = True Catch ex As Exception Debug.WriteLine(ex.Message) End Try End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click LoadDocument("d:\tspcd\mx\801b.htm") End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click LoadDocument("d:\tspcd\mx\snm800.htm") End Sub Private Sub proc_Exited(ByVal sender As Object, ByVal e As System.EventArgs) Handles proc.Exited gblnProcessRunning = False End Sub




Reply With Quote