473,397 Members | 1,950 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,397 software developers and data experts.

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

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
6 1894
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
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
<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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Raj | last post by:
Hi! Every time my applicaiton call "System.Diagnosis.Process.GetProcesses() and some other related APIs in dotnet framework, it throws the following exception: "An unhandled exception of type...
1
by: Mircea Pleteriu | last post by:
Hi all, I want to get the list of active/running processes on some remote machines in the same LAN my application run. I always get a System.InvalidOperationExpection exception with the message...
5
by: Jane | last post by:
Hi, I try Process remoteByName = Process.GetProcesses(); it works but when I try Process remoteByName = Process.GetProcesses("localhost"); it fails with invalid operation please Help me!...
7
by: Denis Brkljacic | last post by:
Hi, I have made some simple ASP.NET (C#) application, that somewhere uses this command: Process aProcesses = Process.GetProcesses(Environment.MachineName); This command purpose is to find...
0
by: Snig | last post by:
Hi I've a simple web application where I need to list all the processes running in the local system. First, my code was generating error: System.ComponentModel.Win32Exception: Access is...
6
by: jcrouse | last post by:
This is kind of a continuation of another thread that was somewhat resolved: Well, the dilemma seems to be this. I want to be able to hide the DOS box AND pause the code until execution is...
2
by: =?Utf-8?B?QW5kZXJzIEJvdmlu?= | last post by:
Hi, I am trying to get the SessionId of processes on a remote machine using System.Diagnostics.Process: foreach (Process p in Process.GetProcesses("remotemachine")) {...
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...
1
by: Rick | last post by:
Can anyone tell me how to set the printer using the process class in VB.net, I've tried everything, it always goes to the default printer. My Code: Dim pathToExecutable As String =...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.