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

eventhandler fires when a process(myProcess.GetProcesses) is missing

P: n/a
Hi,
I want to show a message in my vb.net program when another windows
program (eg calc.exe) is stopped by a user.
with
pList = myProcess.GetProcesses

For Each myProcess In pList
I can check if the program/process is running.

I could use a timer or run the check on every control event, but what I
prefer is a eventhandler that fires when the other program stops.
(sort of push instead of pull mechanism)

Anybody an idea to make such an event handler?
(I only found soms samples with file checking etc)

Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
henk schrieb:
Hi,
I want to show a message in my vb.net program when another windows
program (eg calc.exe) is stopped by a user.
with
pList = myProcess.GetProcesses

For Each myProcess In pList
I can check if the program/process is running.

I could use a timer or run the check on every control event, but what I
prefer is a eventhandler that fires when the other program stops.
(sort of push instead of pull mechanism)

Anybody an idea to make such an event handler?
(I only found soms samples with file checking etc)


You can call process.waitforexit in a seperate thread.
Armin
Nov 21 '05 #2

P: n/a
But if I use waiforexit, my application won't response to anything,
only the exit.
(example:)

Private Sub btnWaitForExit_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnWaitForExit.Click
Dim myProcess As Process =
System.Diagnostics.Process.Start("sample.txt")
myProcess.WaitForExit()
MessageBox.Show("Notepad was closed at: " & myProcess.ExitTime &
"." & System.Environment.NewLine & "Exit Code: " & myProcess.ExitCode)
myProcess.Close()
End Sub

I want to show a message if another, allready running process (eg
calc.exe), stops running. But when the calc.exe process is running, my
vb program must respond to all user actions.

Anybody some example code to help me out?

Nov 21 '05 #3

P: n/a
<co*****@dexternet.nl> schrieb
But if I use waiforexit, my application won't response to anything,
only the exit.
(example:)

Private Sub btnWaitForExit_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnWaitForExit.Click
Dim myProcess As Process =
System.Diagnostics.Process.Start("sample.txt")
myProcess.WaitForExit()
MessageBox.Show("Notepad was closed at: " & myProcess.ExitTime
& "." & System.Environment.NewLine & "Exit Code: " &
myProcess.ExitCode) myProcess.Close()
End Sub

I want to show a message if another, allready running process (eg
calc.exe), stops running. But when the calc.exe process is running,
my vb program must respond to all user actions.

Anybody some example code to help me out?

That's why I wrote "You can call process.waitforexit in a seperate thread.".
In a seperate Thread means, your other/main thread(s) keep on running. If
you only want to show a Messagebox, you can do it after WaitForExit returns.
Otherwise, I would raise an event.
Armin

Nov 21 '05 #4

P: n/a
I made the Thread. (never used threads before but) works great!

One problem:
If my vb.net app finds the calc.exe at form.load.
The thread with the waitforexit starts.
If I close my vb program, it will be closed, but is still
running(taskmanager) and waiting for the "waitforexit" of calc.exe.
Unil I stop calc.exe, my vb app is running.

I tried something with
RemoveHandler MyThreads.LostMedlims, AddressOf myEventHandler
Thread1.Abort()
But my vb app stil is waiting..

Thanks in advance

Nov 21 '05 #5

P: n/a
"henk" <ri*******@hotmail.com> schrieb
I made the Thread. (never used threads before but) works great!

One problem:
If my vb.net app finds the calc.exe at form.load.
The thread with the waitforexit starts.
If I close my vb program, it will be closed, but is still
running(taskmanager) and waiting for the "waitforexit" of calc.exe.
Unil I stop calc.exe, my vb app is running.

I tried something with
RemoveHandler MyThreads.LostMedlims, AddressOf myEventHandler
Thread1.Abort()
But my vb app stil is waiting..

Thanks in advance


I'm afraid, I don't know why Abort doesn't abort the thread.

You can replace WaitForExit by

do until p.WaitForExit(200)
loop
Armin
Nov 21 '05 #6

P: n/a
Aborting the thread works, so my messagebox in my eventhandler will not
be showed. Although, the application still waits for the 'waitforexit'.
I don't know why, but your solution works fine!!
Thanks

Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.