473,569 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Diagnost ics.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(B yVal sender As System.Object, ByVal e As

System.EventArg s) Handles Button4.Click
Dim oProcess As New Process
oProcess.StartI nfo.FileName = "MailTo:" + tbemail.Text
oProcess.StartI nfo.Arguments = ""
' This will allow the Exited event to fire.
oProcess.Enable RaisingEvents = 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(B yVal 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(B yVal sender As System.Object, ByVal e As

System.EventArg s) Handles Button4.Click
Dim oProcess As New Process
' Provide the name of the application or file.
oProcess.StartI nfo.FileName = "Noteopad"
' Specify the arguments.
oProcess.StartI nfo.Arguments = ""
' This will allow the Exited event to fire.
oProcess.Enable RaisingEvents = 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(B yVal 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 3108
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******** *************@m 73g2000cwd.goog legroups.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.Diagnost ics.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(B yVal sender As System.Object, ByVal e As

System.EventArg s) Handles Button4.Click
Dim oProcess As New Process
oProcess.StartI nfo.FileName = "MailTo:" + tbemail.Text
oProcess.StartI nfo.Arguments = ""
' This will allow the Exited event to fire.
oProcess.Enable RaisingEvents = 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(B yVal 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(B yVal sender As System.Object, ByVal e As

System.EventArg s) Handles Button4.Click
Dim oProcess As New Process
' Provide the name of the application or file.
oProcess.StartI nfo.FileName = "Noteopad"
' Specify the arguments.
oProcess.StartI nfo.Arguments = ""
' This will allow the Exited event to fire.
oProcess.Enable RaisingEvents = 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(B yVal 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
5934
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(); p10.StartInfo.FileName = "cmd.exe"; p10.StartInfo.UseShellExecute = false; // p.StartInfo.CreateNoWindow = true; p10.StartInfo.RedirectStandardInput = true;
14
8779
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 thrown as the program should. here's my code for A.exe procEXE = Process.Start(PROGRAM_NAME procEXE.WaitForExit( If procEXE.HasExited The If...
8
15947
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 it needs to return an exit code to that script. I've tried a few ways to return an exit code. 1. As a forms app with Entry point being Form1,...
4
2794
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 & "WksBkup.txt""" WinZip.Start("c:\Program Files\WinZip\wzzip.exe", args) WinZip.WaitForExit() Do If WinZip.HasExited = True Then Exit Do Loop
1
2394
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 it is not. I have placed WaitForExit(20000) to limit the execution time to 20 seconds and if it does not terminate then it will be forced close. The...
2
2119
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 class and WaitForExit() to start it and wait till it rsponds me. It's necessary for the application to get a response, that's why I use...
4
8474
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 execute even a simple VB.Net windows application. No error is being returned. The application just can't be opened (even it is not found inside Task...
9
18863
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 process is zero. I tried using the following, but it goes to catch.
8
2059
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. system.diagnostics.process instApp = system.diagnostics.process.start("Setup.exe"); instApp.WaitForExit(); //code that is dependent upon the...
0
7695
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7922
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
6281
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5218
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.