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

Not getting process state

P: n/a
Hi,
I am starting a process and I need to monitor it (wait and check if its
still responding).

But, I it seems that the Process.HasExited or Process.Exited doesn't work.

I just need to know if the process is running & responding.

I am using

void somefn(...)
{
if(...)
{
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = this.Path;
psi.Arguments = this.CreateArguments();
psi.ErrorDialog = false;
psi.UseShellExecute = true; //tried with false also
Process p = Process.Start(psi);

p.Exited += new EventHandler(Exited);
while (p.HasExited)
{
Thread.Sleep(1000);
}
}
return Success;
}

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

The execution never enters the while loop nor the Exited method is called.

Any ideas???

Regards,
Ashutosh
Jun 27 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
On Thu, 15 May 2008 00:19:55 +0530, Ashutosh Bhawasinka
<sm*******@nospam.nospamwrote:
>Hi,
I am starting a process and I need to monitor it (wait and check if its
still responding).

But, I it seems that the Process.HasExited or Process.Exited doesn't work.

I just need to know if the process is running & responding.

I am using

void somefn(...)
{
if(...)
{
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = this.Path;
psi.Arguments = this.CreateArguments();
psi.ErrorDialog = false;
psi.UseShellExecute = true; //tried with false also
Process p = Process.Start(psi);

p.Exited += new EventHandler(Exited);
Hmm, try swapping the two lines above ...
while (p.HasExited)
Don't you mean while(!p.HasExited)?

{
Thread.Sleep(1000);
}
}
return Success;
}

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

The execution never enters the while loop nor the Exited method is called.

Any ideas???
See above ...

Regards,
Gilles.

Jun 27 '08 #2

P: n/a
Hi,
Thanks for pointing out the mistake....it's such a silly one :)

Actually, I was more interested in the callback. Do, you have any clue
on that??

Regards,
Ashutosh

Gilles Kohl [MVP] wrote:.
On Thu, 15 May 2008 00:19:55 +0530, Ashutosh Bhawasinka
<sm*******@nospam.nospamwrote:
>Hi,
I am starting a process and I need to monitor it (wait and check if its
still responding).

But, I it seems that the Process.HasExited or Process.Exited doesn't work.

I just need to know if the process is running & responding.

I am using

void somefn(...)
{
if(...)
{
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = this.Path;
psi.Arguments = this.CreateArguments();
psi.ErrorDialog = false;
psi.UseShellExecute = true; //tried with false also
Process p = Process.Start(psi);

p.Exited += new EventHandler(Exited);

Hmm, try swapping the two lines above ...
> while (p.HasExited)

Don't you mean while(!p.HasExited)?

> {
Thread.Sleep(1000);
}
}
return Success;
}

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

The execution never enters the while loop nor the Exited method is called.

Any ideas???

See above ...

Regards,
Gilles.
Jun 27 '08 #3

P: n/a
On May 14, 4:03 pm, Ashutosh Bhawasinka <smbs-m...@nospam.nospam>
wrote:
Hi,
Thanks for pointing out the mistake....it's such a silly one :)

Actually, I was more interested in the callback. Do, you have any clue
on that??

Regards,
Ashutosh

Gilles Kohl [MVP] wrote:.
On Thu, 15 May 2008 00:19:55 +0530, Ashutosh Bhawasinka
<smbs-m...@nospam.nospamwrote:
Hi,
I am starting a process and I need to monitor it (wait and check if its
still responding).
But, I it seems that the Process.HasExited or Process.Exited doesn't work.
I just need to know if the process is running & responding.
I am using
void somefn(...)
{
if(...)
{
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = this.Path;
psi.Arguments = this.CreateArguments();
psi.ErrorDialog = false;
psi.UseShellExecute = true; //tried with false also
Process p = Process.Start(psi);
p.Exited += new EventHandler(Exited);
Hmm, try swapping the two lines above ...
while (p.HasExited)
Don't you mean while(!p.HasExited)?
{
Thread.Sleep(1000);
}
}
return Success;
}
void Exited(object sender, EventArgs e)
{
MessageBox.Show("Done");
}
The execution never enters the while loop nor the Exited method is called.
Any ideas???
See above ...
Regards,
Gilles.
That mite fix your problem. GC was probably taking your object
(process) since you were not waiting in that loop and that might be
the reason why Exited never got called..
Jun 27 '08 #4

P: n/a
>Thanks for pointing out the mistake....it's such a silly one :)
>
Actually, I was more interested in the callback. Do, you have any clue
on that??
Try adding

p.EnableRaisingEvents = true;

Regards,
Gilles.

Jun 27 '08 #5

P: n/a
Thanks all who help on this issue!

Hi Ashutosh,

In summary, there're three problems in your sample code snippet.

1. You should set the EnableRaisingEvents property of the Process to true
for the Process component to receive notification that the process has
exited.

2. You should subscribe the Exited event of the Process before call the
Start method of the Process.

3. Change the condition in the while statement to "!p.HasExited" within the
"somefn" method.

For more information about the Process's Exited event, please refer to the
following MSDN document:
https://msdn2.microsoft.com/en-us/li...process.exited.
aspx

Hope this helps.
If you have anything unclear, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Jun 27 '08 #6

P: n/a
Thanks everyone for your help. The issue is resolved now.

Looks like I was sleeping while writing that code :)

Regards,
Ashutosh

Linda Liu[MSFT] wrote:
Thanks all who help on this issue!

Hi Ashutosh,

In summary, there're three problems in your sample code snippet.

1. You should set the EnableRaisingEvents property of the Process to true
for the Process component to receive notification that the process has
exited.

2. You should subscribe the Exited event of the Process before call the
Start method of the Process.

3. Change the condition in the while statement to "!p.HasExited" within the
"somefn" method.

For more information about the Process's Exited event, please refer to the
following MSDN document:
https://msdn2.microsoft.com/en-us/li...process.exited.
aspx

Hope this helps.
If you have anything unclear, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 27 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.