Catch Application After Exit (WaitforExit) VB.Net

P

Pete

Hi All,

I'm new to this so please correct me if I'm wrong. I have written a
small program which holds details for task information. the program
holds an email address, i created a button which use
System.Diagnostics.Process class in vb.net to start a "Mailto:" + email

address. This works fine, however I wanted to expand on this some more
when the user had sent the email I wanted to do something afterwards.
so looked around and found some code which raises an exit event when
the original event has exited. It works fine when launching something
like notepad.exe, but when I put my mailto command in it does not fire
the exit event. Below I have included the code working and the code not

working.


In advance thanks,


Pete.


Will not work with the below code:


Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As

System.EventArgs) Handles Button4.Click
Dim oProcess As New Process
oProcess.StartInfo.FileName = "MailTo:" + tbemail.Text
oProcess.StartInfo.Arguments = ""
' This will allow the Exited event to fire.
oProcess.EnableRaisingEvents = True
' Add an event handler for this process.
' Run the OnProcessExit sub when this process exits.
AddHandler oProcess.Exited, AddressOf OnProcessExit
' Start the process.
oProcess.Start()


End Sub
Private Sub OnProcessExit(ByVal sender As Object, ByVal e As
EventArgs)
' Avoid late binding and Cast the Object to a Process.
Dim proc As Process = CType(sender, Process)
' Write the ExitCode
Debug.WriteLine(proc.ExitCode)
' Write the ExitTime
Debug.WriteLine(proc.ExitTime.ToString)
MessageBox.Show("exited")
End Sub
End Class


Will work with the below code:


Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As

System.EventArgs) Handles Button4.Click
Dim oProcess As New Process
' Provide the name of the application or file.
oProcess.StartInfo.FileName = "Noteopad"
' Specify the arguments.
oProcess.StartInfo.Arguments = ""
' This will allow the Exited event to fire.
oProcess.EnableRaisingEvents = True
' Add an event handler for this process.
' Run the OnProcessExit sub when this process exits.
AddHandler oProcess.Exited, AddressOf OnProcessExit
' Start the process.
oProcess.Start()


End Sub
Private Sub OnProcessExit(ByVal sender As Object, ByVal e As
EventArgs)
' Avoid late binding and Cast the Object to a Process.
Dim proc As Process = CType(sender, Process)
' Write the ExitCode
Debug.WriteLine(proc.ExitCode)
' Write the ExitTime
Debug.WriteLine(proc.ExitTime.ToString)
MessageBox.Show("exited")
End Sub
End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top