473,412 Members | 2,067 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Catch Application After Exit (WaitforExit) VB.Net

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

Aug 21 '06 #1
1 3087
Pete,

Tom has made some days ago a nice better working sample for your problem.

http://groups.google.com/group/micro...837d41bb5bb22c

I hope this hlps,

Cor

"Pete" <ba***@hotmail.comschreef in bericht
news:11*********************@m73g2000cwd.googlegro ups.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

Aug 21 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: jam | last post by:
Dear All, I have a command process running xcopy in console, and now I want to execute the program Rsync After the files are copied...how could i do?? Process p10=new Process();...
14
by: libs | last post by:
I have A.exe that should catch the return code of B.exe (both are written in VB.net) so A.exe can continue processing other commands. but A.exe cannot catch B's return code so an exception is not...
8
by: Zeno Lee | last post by:
What is the best way to return an exit code from a VB.NET windows forms app? My Forms application is dual purpose. It is an interactive windows app. It is also automated and run via a script and...
4
by: Terry Olsen | last post by:
I have loop that calls a Sub that runs the following code: Dim WinZip As System.Diagnostics.Process Dim args As String = " -Pru -ex " & lblFolder.Text & "\" & PCName & ".zip @""" & appPth &...
1
by: chad | last post by:
Hi, I am using Process.Start() to call a console application from ASP.NET page. When the code is executed, the Console application is opened. When it is done, it should have been terminated but...
2
by: Lonifasiko | last post by:
Hi group, I must launch from my Winforms application another application (.exe developed by the client) which response time sometimes can be more or less 30 seconds. I'm using ProcessManager...
4
by: =?Utf-8?B?TEJU?= | last post by:
Good day, I would like to execute an external application from a web form created using ASP.Net. I'm using System.Diagnostics.Process. It works fine if it is notepad.exe but it is not able to...
9
by: Eran.Yasso | last post by:
Hi, My app starts process. Some times this process exits because of exception. Can my app know if the process exited due to exception or gracefully? In both ways, the exit code of this...
8
by: TxAg03 | last post by:
I ran an outside program that launched another program. I created a process for the launcher program and waited for that to exit, but what I need is to have it wait for the 2nd program to exit. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.