|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Catch Application After Exit (WaitforExit) VB.NetI'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 Pete,
Tom has made some days ago a nice better working sample for your problem. http://groups.google.com/group/microsoft.public.dotnet.languages.vb/msg/2a837d41bb5bb22c I hope this hlps, Cor Show quoteHide quote "Pete" <ba***@hotmail.com> schreef in bericht news:1156148319.985005.24710@m73g2000cwd.googlegroups.com... > 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 > |
|||||||||||||||||||||||