471,325 Members | 1,592 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,325 software developers and data experts.

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 13235
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by serge calderara | last post: by
18 posts views Thread by jas | last post: by
4 posts views Thread by rawCoder | last post: by
3 posts views Thread by Chris Dunaway | last post: by
7 posts views Thread by Christian Cambier | last post: by
reply views Thread by rosydwin | last post: by

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.