473,473 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Raising process exit event

WRH
Hello
I used the VS designer to set up Process code as follows...
the problem is, although the process is executed, when
it is shut down I never get the Exited event.
....
private System.Diagnostics.Process process1;
....
this.process1 = new System.Diagnostics.Process();
....

// process1
//
this.process1.EnableRaisingEvents = true;
this.process1.SynchronizingObject = this;
this.process1.Exited += new System.EventHandler(this.process1_Exited);
....
process1.StartInfo.FileName = @"F:\G\MS Paint";
process1.Start();

....

private void process1_Exited(object sender, System.EventArgs e)
{
MessageBox.Show("Exited");
}
Feb 6 '06 #1
3 13441
WRH
Problem solved. It turns out that if the process is a shortcut,
ie .lnk then the process runs but does not raise the event.

"WRH" <no*****@videotron.ca> wrote in message
news:uY*************@tk2msftngp13.phx.gbl...
Hello
I used the VS designer to set up Process code as follows...
the problem is, although the process is executed, when
it is shut down I never get the Exited event.
...
private System.Diagnostics.Process process1;
...
this.process1 = new System.Diagnostics.Process();
...

// process1
//
this.process1.EnableRaisingEvents = true;
this.process1.SynchronizingObject = this;
this.process1.Exited += new System.EventHandler(this.process1_Exited);
...
process1.StartInfo.FileName = @"F:\G\MS Paint";
process1.Start();

...

private void process1_Exited(object sender, System.EventArgs e)
{
MessageBox.Show("Exited");
}

Feb 6 '06 #2
WRH,

That should work perfectly. In order to get that event fired you need to set
EnableRaisingEvents = true; I can see you did that.

My suggestion is to double check if this flag is set.

Another case where you may not get the event fired (I just want to make
clear that this is very unlikely and I don't believe this is your problem)
is because you set SynchronizingObject to the parent control. In this case
the code will try to marshal the event call to the UI thread. Internally
this is done using the windows message loop and it should work perfectly.
There might be a catch though. If the parent control is a user control for
example and the control is created using the *new* operator, but not added
to any Controls collection it might be possible that the message loop
doesn't serve these control or the control might be created in a worker
theread that has no message loop at all. Again this is very hypothetical,
but there are chances that you may recognize similar situation in your code.
--
HTH
Stoitcho Goutsev (100)

"WRH" <no*****@videotron.ca> wrote in message
news:uY*************@tk2msftngp13.phx.gbl...
Hello
I used the VS designer to set up Process code as follows...
the problem is, although the process is executed, when
it is shut down I never get the Exited event.
...
private System.Diagnostics.Process process1;
...
this.process1 = new System.Diagnostics.Process();
...

// process1
//
this.process1.EnableRaisingEvents = true;
this.process1.SynchronizingObject = this;
this.process1.Exited += new System.EventHandler(this.process1_Exited);
...
process1.StartInfo.FileName = @"F:\G\MS Paint";
process1.Start();

...

private void process1_Exited(object sender, System.EventArgs e)
{
MessageBox.Show("Exited");
}

Feb 7 '06 #3
WRH
Thanks for the response and the info. I did find this particular problem and
posted this note...

Problem solved. It turns out that if the process is a shortcut,
ie .lnk then the process runs but does not raise the event.

"Stoitcho Goutsev (100)" <10*@100.com> wrote in message
news:u1*************@tk2msftngp13.phx.gbl...
WRH,

That should work perfectly. In order to get that event fired you need to
set EnableRaisingEvents = true; I can see you did that.

My suggestion is to double check if this flag is set.

Another case where you may not get the event fired (I just want to make
clear that this is very unlikely and I don't believe this is your problem)
is because you set SynchronizingObject to the parent control. In this case
the code will try to marshal the event call to the UI thread. Internally
this is done using the windows message loop and it should work perfectly.
There might be a catch though. If the parent control is a user control for
example and the control is created using the *new* operator, but not added
to any Controls collection it might be possible that the message loop
doesn't serve these control or the control might be created in a worker
theread that has no message loop at all. Again this is very hypothetical,
but there are chances that you may recognize similar situation in your
code.
--
HTH
Stoitcho Goutsev (100)

"WRH" <no*****@videotron.ca> wrote in message
news:uY*************@tk2msftngp13.phx.gbl...
Hello
I used the VS designer to set up Process code as follows...
the problem is, although the process is executed, when
it is shut down I never get the Exited event.
...
private System.Diagnostics.Process process1;
...
this.process1 = new System.Diagnostics.Process();
...

// process1
//
this.process1.EnableRaisingEvents = true;
this.process1.SynchronizingObject = this;
this.process1.Exited += new System.EventHandler(this.process1_Exited);
...
process1.StartInfo.FileName = @"F:\G\MS Paint";
process1.Start();

...

private void process1_Exited(object sender, System.EventArgs e)
{
MessageBox.Show("Exited");
}


Feb 7 '06 #4

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

Similar topics

4
by: serge calderara | last post by:
Dear all, I have a class wich is raising events as normally it should do. having a form in the same assembly wich is catching those events works fne. Raise events gets catch normaly within the...
18
by: jas | last post by:
Hi, I would like to start a new process and be able to read/write from/to it. I have tried things like... import subprocess as sp p = sp.Popen("cmd.exe", stdout=sp.PIPE)...
3
by: David | last post by:
Hi, Ive been trying to work this out for the past 2 days now and im not getting anywhere fast. The problem i have is that i am using Asynchronous sockets to create a Socket Client library....
6
by: Dan | last post by:
I've created a pocketpc app which has a startup form containing a listview. The form creates an object which in turn creates a System.Threading.Timer. It keeps track of the Timer state using a...
4
by: rawCoder | last post by:
Hi all, How Can You Raise Events Asynchronously ? Now for the details ... I want to do inter modular communication using events in such a way that the contributing modules need not...
3
by: Chris Dunaway | last post by:
Consider the following simple classes/interfaces defined below. When the derived class raises the events, on which thread is the event code run? Do I need to do anything to catch the events in my...
3
by: Woo Mun Foong | last post by:
I have a checkbox, when enable, allows me to proceed with what I like to do. However, I need to check a certain conditions before I allow the checked box to be checked, if condition is not fullfill...
4
by: Nick | last post by:
Hi there, I'm running a process object within a .NET app, very simple, the process is declared with events, i'm handling the Exit event and running a win32 application. No matter how the...
7
by: Christian Cambier | last post by:
Hi, I have a textbox in a web user control. I then add the usercontrol to a web form. I also add a label in the web form. Now, when I press a key in the textbox, i want to display some text...
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
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.