By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,914 Members | 1,718 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,914 IT Pros & Developers. It's quick & easy.

How to know when external process has exited

P: n/a
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
Share this Question
Share on Google+
9 Replies


P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.