473,397 Members | 2,099 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.

Not getting process state

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

Similar topics

3
by: Trevor Andrew | last post by:
Hi There, I have a small ASP.NET application under development. I am using VS.NET 2002 (2003 upgrade is on the way) with .NET Framework 1.1. It is hosted on a web hosting service in the US. I am...
4
by: Chad Crowder | last post by:
I've taken a look at this article http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspnet/html/asp12282000.asp which someone posted a month or so ago regarding setting up SQL...
4
by: dhnriverside | last post by:
Hi peeps I'm having some problems with my Session State sticking (it keeps resetting itself) - I haven't looked into it yet, but I was wondering about using SQL Server as an out of process state...
0
by: Filipe Marcelino | last post by:
Hi, I whant to know if a user is using a process. To achieve that I have to know the state of the process, so I wrote the following code: Dim localAll As Process() =...
4
by: TS | last post by:
in my web project's bin folder, the dll, that comes from a project reference of a class library in same solution, can't be deleted. it says it has a sharing violation. i also cannot delete the...
33
by: JamesB | last post by:
I am writing a service that monitors when a particular app is started. Works, but I need to get the user who is currently logged in, and of course Environment.UserName returns the service logon...
2
by: rustyc | last post by:
Well, here's my first post in this forum (other than saying 'HI' over in the hi forum ;-) As I said over there: ... for a little side project at home, I'm writing a ham radio web site in...
5
by: knyghtfyre | last post by:
Hello, My company is developing a rather large application with .NET 2.0. We are expanding to a server farm and are in the process of converting our application to use an out-of-process session...
1
by: bhavanirayala | last post by:
Hi, I am sending the values from one method to another method to get the values from xml file based on the inputs. I am getting the error like:: Variable "$collType" will not stay shared...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
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,...
0
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...

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.