473,398 Members | 2,343 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,398 software developers and data experts.

How to know when external process has exited

Hello,
I want to automate something and display a simple msgbox that
indicates my external process finished processing and "exited".

My code is that, what things should i add more:

Dim psInfo As New System.Diagnostics.ProcessStartInfo("bla.exe", "-b
")
psInfo.WindowStyle =
System.Diagnostics.ProcessWindowStyle.Normal
psInfo.WorkingDirectory = Application.StartupPath
psInfo.WindowStyle = ProcessWindowStyle.Normal
Dim myProcess As Process =
System.Diagnostics.Process.Start(psInfo)
Thanks...

Oct 10 '07 #1
9 7628
"kimiraikkonen" <ki*************@gmail.comschrieb:
I want to automate something and display a simple msgbox that
indicates my external process finished processing and "exited".

My code is that, what things should i add more:

Dim psInfo As New System.Diagnostics.ProcessStartInfo("bla.exe", "-b
")
psInfo.WindowStyle =
System.Diagnostics.ProcessWindowStyle.Normal
psInfo.WorkingDirectory = Application.StartupPath
psInfo.WindowStyle = ProcessWindowStyle.Normal
Dim myProcess As Process =
System.Diagnostics.Process.Start(psInfo)
\\\
myProcess.WaitForExit()
....
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Oct 10 '07 #2
On Oct 11, 12:15 am, "Herfried K. Wagner [MVP]" <hirf-spam-me-
h...@gmx.atwrote:
"kimiraikkonen" <kimiraikkone...@gmail.comschrieb:
I want to automate something and display a simple msgbox that
indicates my external process finished processing and "exited".
My code is that, what things should i add more:
Dim psInfo As New System.Diagnostics.ProcessStartInfo("bla.exe", "-b
")
psInfo.WindowStyle =
System.Diagnostics.ProcessWindowStyle.Normal
psInfo.WorkingDirectory = Application.StartupPath
psInfo.WindowStyle = ProcessWindowStyle.Normal
Dim myProcess As Process =
System.Diagnostics.Process.Start(psInfo)

\\\
myProcess.WaitForExit()
...
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Yes, but i've forgotten, i don't want to use waitforexit() because it
makes my project's main form unusable/hang while external process is
in progres.

Also i want to autoamate it, i don't know it's about looping
(iteration) or other. I don't want user prompt like button click. How?
I hope explained clear enough.

Oct 10 '07 #3
On Oct 10, 3:44 pm, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Oct 11, 12:15 am, "Herfried K. Wagner [MVP]" <hirf-spam-me-

h...@gmx.atwrote:
"kimiraikkonen" <kimiraikkone...@gmail.comschrieb:
I want to automate something and display a simple msgbox that
indicates my external process finished processing and "exited".
My code is that, what things should i add more:
Dim psInfo As New System.Diagnostics.ProcessStartInfo("bla.exe", "-b
")
psInfo.WindowStyle =
System.Diagnostics.ProcessWindowStyle.Normal
psInfo.WorkingDirectory = Application.StartupPath
psInfo.WindowStyle = ProcessWindowStyle.Normal
Dim myProcess As Process =
System.Diagnostics.Process.Start(psInfo)
\\\
myProcess.WaitForExit()
...
///
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Yes, but i've forgotten, i don't want to use waitforexit() because it
makes my project's main form unusable/hang while external process is
in progres.

Also i want to autoamate it, i don't know it's about looping
(iteration) or other. I don't want user prompt like button click. How?
I hope explained clear enough.- Hide quoted text -

- Show quoted text -
Set the process objects EnableRaisingEvents, and then hook it's Exited
event.

Private WithEvents myProcess As New Process()

Private Sub DoCoolStuff()
With myProcess
.StartInfo.WindowStyle =
System.Diagnostics.ProcessWindowStyle.Normal
.StartInfo.WorkingDirectory = Application.StartupPath
.StartInfo.WindowStyle = ProcessWindowStyle.Normal
.EnableRaisingEvents = True
End With
myProcess.Start()
End Sub

Private Sub ProcessExited (Byval sender As Object, ByVal e As
System.EventArgs) Handles myProcess.Exited
' do cool stuff
End Sub

Anyway, not a complete working example, but it should give you the
idea.

--
Tom Shelton

Oct 10 '07 #4
Kimi,

You can beside the wait for exist as well use the given back output
information.

See for that the Google sample on this webpage.

http://www.vb-tips.com/dbpages.aspx?Search=start

Cor

Oct 11 '07 #5
On Oct 10, 4:01 pm, kimiraikkonen <kimiraikkone...@gmail.comwrote:
Hello,
I want to automate something and display a simple msgbox that
indicates my external process finished processing and "exited".

My code is that, what things should i add more:

Dim psInfo As New System.Diagnostics.ProcessStartInfo("bla.exe", "-b
")
psInfo.WindowStyle =
System.Diagnostics.ProcessWindowStyle.Normal
psInfo.WorkingDirectory = Application.StartupPath
psInfo.WindowStyle = ProcessWindowStyle.Normal
Dim myProcess As Process =
System.Diagnostics.Process.Start(psInfo)

Thanks...
Perhaps you should re-read your previous posts. Armin has already told
you how to do this and even provided a sample....

http://groups.google.com/group/micro...15f878e987caaa

Thanks,

Seth Rowe

Oct 11 '07 #6
On Oct 11, 1:55 pm, rowe_newsgroups <rowe_em...@yahoo.comwrote:
On Oct 10, 4:01 pm, kimiraikkonen <kimiraikkone...@gmail.comwrote:
Hello,
I want to automate something and display a simple msgbox that
indicates my external process finished processing and "exited".
My code is that, what things should i add more:
Dim psInfo As New System.Diagnostics.ProcessStartInfo("bla.exe", "-b
")
psInfo.WindowStyle =
System.Diagnostics.ProcessWindowStyle.Normal
psInfo.WorkingDirectory = Application.StartupPath
psInfo.WindowStyle = ProcessWindowStyle.Normal
Dim myProcess As Process =
System.Diagnostics.Process.Start(psInfo)
Thanks...

Perhaps you should re-read your previous posts. Armin has already told
you how to do this and even provided a sample....

http://groups.google.com/group/micro...languages.vb/b...

Thanks,

Seth Rowe
Seth,
Yes i know, but i couldn't manage to do. I added another "private sub
onProcess Exited..." as corrected by Visual Studio.
Then i run my project but at the end of processing, nothing happened.?

Oct 11 '07 #7
On Oct 11, 7:10 am, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Oct 11, 1:55 pm, rowe_newsgroups <rowe_em...@yahoo.comwrote:


On Oct 10, 4:01 pm, kimiraikkonen <kimiraikkone...@gmail.comwrote:
Hello,
I want to automate something and display a simple msgbox that
indicates my external process finished processing and "exited".
My code is that, what things should i add more:
Dim psInfo As New System.Diagnostics.ProcessStartInfo("bla.exe", "-b
")
psInfo.WindowStyle =
System.Diagnostics.ProcessWindowStyle.Normal
psInfo.WorkingDirectory = Application.StartupPath
psInfo.WindowStyle = ProcessWindowStyle.Normal
Dim myProcess As Process =
System.Diagnostics.Process.Start(psInfo)
Thanks...
Perhaps you should re-read your previous posts. Armin has already told
you how to do this and even provided a sample....
http://groups.google.com/group/micro...languages.vb/b...
Thanks,
Seth Rowe

Seth,
Yes i know, but i couldn't manage to do. I added another "private sub
onProcess Exited..." as corrected by Visual Studio.
Then i run my project but at the end of processing, nothing happened.?- Hide quoted text -

- Show quoted text -
Did you set your process objects EnableRaisingEvetns property to
true? Otherwise, no event will be raised....

--
Tom Shelton

Oct 11 '07 #8
Did you set your process objects EnableRaisingEvetns property to
true? Otherwise, no event will be raised....

--
Tom Shelton
Tom, thanks! That's it! It fixed determining about exiting event, but
another problem:

if i want to hide my visible progess bar by coding
"progressbar1.hide()" just before MsgBox("exited") i get that error:

"Cross-thread operation not valid: Control 'ProgressBar1' accessed
from a thread other than the thread it was created on."

How can i fix it though?

Very thanks

Oct 11 '07 #9
On Oct 11, 10:15 am, kimiraikkonen <kimiraikkone...@gmail.comwrote:
Did you set your process objects EnableRaisingEvetns property to
true? Otherwise, no event will be raised....
--
Tom Shelton

Tom, thanks! That's it! It fixed determining about exiting event, but
another problem:

if i want to hide my visible progess bar by coding
"progressbar1.hide()" just before MsgBox("exited") i get that error:

"Cross-thread operation not valid: Control 'ProgressBar1' accessed
from a thread other than the thread it was created on."

How can i fix it though?

Very thanks
You must marshal control back to the form. The easiest way (imo) is to
use Me.BeginInvoke.

Here's another sample that you need to place in the code-behind of
Form1 in a new Windows Application

////////////////////
Imports System.Threading

Public Class Form1
Private progress As ProgressBar

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
progress = New ProgressBar()
progress.Location = New Point(3, 3)
Me.Controls.Add(progress)

Dim button As New Button()
button.Location = New Point(3, 30)
button.Size = New Size(75, 23)
button.Text = "Begin Work"

AddHandler button.Click, AddressOf button_Click

Me.Controls.Add(button)
End Sub

Private Sub button_Click(ByVal sender As Object, ByVal e As
EventArgs)
Dim t As New Thread(AddressOf DoTheWork)
t.Start()
End Sub

Private Sub DoTheWork()
Try
'// Do something useful
MessageBox.Show("Doing something useful")
Finally
If Me.InvokeRequired Then
Dim d As New HideProgressBarDelegate(AddressOf
HideProgressBar)
Me.BeginInvoke(d)
Else
HideProgressBar()
End If
End Try
End Sub

Private Delegate Sub HideProgressBarDelegate()

Private Sub HideProgressBar()
progress.Hide()
End Sub

End Class
////////////////////

Thanks,

Seth Rowe

Oct 11 '07 #10

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

Similar topics

0
by: Daniel Xiao | last post by:
I have used the following method to set the running priority for a process and its affiliated threads. It is noticable at statement (*) that if the process has already exited, the method will...
1
by: solex | last post by:
Hello All, Hopefully someone has run into this error. I have written a class(source below) that launches a thread to monitor the StandardOutput of a System.Diagnostics.Process, in particular I...
5
by: snicks | last post by:
I'm trying to exec a program external to my ASP.NET app using the following code. The external app is a VB.NET application. Dim sPPTOut As String sPPTOut = MDEPDirStr + sID + ".ppt" Dim p As...
16
by: Caroline | last post by:
I am building a web application to gather user information then launch a process to calculate results. The process is a 3rd Party executable. I cannot get the process to start. Is there a...
7
by: Bob | last post by:
Process.start("Mydoc.doc") starts Word with the file. I need to wait for Word to be closed before more code can execute in my app. How can I do this? Thanks for any help Bob
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...
8
by: Lonifasiko | last post by:
Hi, Using Process class I asynchronously launch an executable (black box executable) file from my Windows application. I mean asynchronously because I've got an EventHandler for "Exited" event....
5
by: ags5406 | last post by:
I've a Windows Service that keeps a particular executable running. If the executable fails for whatever reason, the Service restarts it. Right now I'm using a loop to check if the process is...
0
by: John Halet | last post by:
I have a application that crunches a bunch of data, creating log files, excel files etc... I use Process.Start to open any number of these file for viewing. My goal is to have the application...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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,...
0
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...
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.