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

  • Thread starter Thread starter henk
  • Start date Start date
H

henk

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)
 
henk said:
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
 
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?
 
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
 
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
 
henk said:
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top