473,320 Members | 2,122 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,320 software developers and data experts.

Check if process has started

How can I query a new process to determine if it has started yet? For
example:

using System.Diagnostics;
Process cmd = new Process();
cmd.StartInfo = new ProcessStartInfo();
..
..
..
if (!cmd.HasStarted) Response.Write("The process hasn't started yet");
else Response.Write ("The process is running");

I know the .HasStarted property doesn't exist, but what method can be
used to determine if the process object is running?

The HasExited property returns an Invalid Operation Exception if a
..Start hasn't been issued. I could catch the exception and handle it
that way but I don't like catching exceptions as a way of handling
coding issues.

Jun 2 '06 #1
2 12018
Hi Corbett,

I understand you don't like provoking exceptions to write your code but
sometimes, as far as I know, they're all you've got.

Take a look at the following code for some ideas, I understand there's
an exception - but there is no attempt to handle it.

int nId = 0;
Process process = new Process ();
process.StartInfo = new ProcessStartInfo("notepad.exe");
process.Start();

try
{
if (process.Id != 0 && !process.HasExited )
{
// its started
Debug.Assert(true);
}
nId = process.Id;
}
catch{}

if (nId > 0)
{
Process[] processes =
Process.GetProcessesByName("notepad");
foreach (Process proc in processes)
{
if (proc.Id == nId )
{
Debug.Assert(true);
}
}
}

Jun 2 '06 #2
Thanks for confirming that catching the exception is really the only
way to accomplish what I'm trying to do. For the record, here is the
method that I ended up creating:

public static bool IsRunning(System.Diagnostics.Process proc)
{
try
{
return (!proc.HasExited && proc.Id != 0);
}
catch
{
return false;
}
}

Jun 2 '06 #3

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

Similar topics

1
by: Peter Åstrand | last post by:
There's a new PEP available: PEP 324: popen5 - New POSIX process module A copy is included below. Comments are appreciated. ---- PEP: 324 Title: popen5 - New POSIX process module
5
by: Jon Perez | last post by:
Running the following under Linux creates 3 processes instead of 2. Once the started thread exits, 2 processes still remain. Why? import thread from thread import start_new_thread def...
11
by: Wolfgang Kaml | last post by:
Hello All, I have been working on this for almost a week now and I haven't anything up my sleeves anymore that I could test in addition or change.... Since I am not sure, if this is a Windows...
12
by: serge calderara | last post by:
Dear all, I have an application which is suppose to start another executable process. As soon as that process is running, I need to retrive its handle. The problem of the particular process I am...
3
by: DAMAR | last post by:
Hello Is it possible to know when a particular process started? For example: I have such situation: I need to know when a notepad.exe is started - i need to get an event of starting this...
11
by: Jon Davis | last post by:
Does anyone know why using System.Diagnostics.Process to "wrap" a console application does not always transmit the I/O, depending on what processes you're trying to "consume"? PowerShell, for...
2
by: Dax | last post by:
Does anyone know if there's a means by which I can invoke a Process.Start, then detach the process from the calling process. I suppose in a nutshell I'm asking if there's a way I can add the new...
2
by: test3 | last post by:
Hello folks, I'm using System.Diagnostics.Process to start a thirdparty program (that works perfectly when started via command line). I'm using Process.StandardOutput to get the output of the...
5
by: ags5406 | last post by:
I've a Windows Service that keeps a particular executable running. If the executable fails for whatever reason, the Service restarts it. Right now I'm using a loop to check if the process is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.