Reputation: 461
After searching alot regarding this issue, I'm still facing problems in checking whether the running process has finished or not. When the user hit the 'Go' button in the GUI, the program is running for about 5 seconds and closes. When it is finished, I want to do something (e.g., green mark in GUI).
My problem is the 'GetProcessesByName' apparently cannot see the program, which is strange, because I see it in the task manager. The program name is quartus_pgm.exe
. See the following code, I've tried quartus_pgm
, or quartus_pgm.exe
, or quartus_pgm.exe32
(as seen in the task manager) but nothing!
If I put 'cmd' it does see it (the quartus_pgm is envoked from the cmd), but it is not what i'm looking for. I've tried various methods:
Process[] targetProcess = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(processName));
or this one:
Process[] processes = Process.GetProcessesByName("quartus_pgm");
if (processes.Length > 0)
// do something;
or this one:
foreach (var process in Process.GetProcessesByName("quartus_pgm.exe"))
{
// do something;
}
Upvotes: 14
Views: 25304
Reputation: 18569
Try remove .exe
part.
foreach (var process in Process.GetProcessesByName("quartus_pgm"))
{
// do something;
}
From here :
The process name is a friendly name for the process, such as Outlook, that does not include the .exe extension or the path
UPDATE
Try to list all of process in your machine, look for the quartus_pgm
process name.
foreach (var process in Process.GetProcesses())
{
Console.WriteLine(process.ProcessName);
}
Upvotes: 36
Reputation: 63732
Since you're already starting the process yourself, why not just keep the Process
reference to it? Then you can just do
if (process.HasExited) { ... }
(don't forget you have to call process.Refresh
to make sure the HasExited
property is updated properly)
Or even just wait on it's wait handle (ideally using asynchronous code).
Upvotes: 1
Reputation: 723
Any chance that this method is case sensitive? If you loop through the processes, do you find it?
foreach (Process p in Process.GetProcesses())
{
if (p.ProcessName.ToLower() == "quartus_pgm")
{
}
}
Upvotes: 3