Process.Start() and Process.WaitForExit()

C

Chris

Hello,

I have a Windows Forms application which has buttons to click to run
other programs.

One of the applications it must run is a ClickOnce Windows Forms
application, so the Application Reference in the start menu is the only
way to access it.

I have the following code used to start the other program:

System.Diagnostics.Process _proc;
string ExecutableName;

ExecutableName = "C:\\Documents and
Settings\\User\\Start Menu\\Programs\\App1\\App1.appref-ms";
_proc = new System.Diagnostics.Process();
_proc.StartInfo.FileName = ExecutableName;
_proc.StartInfo.UseShellExecute = true;
_proc.StartInfo.WindowStyle =
ProcessWindowStyle.Normal;
_proc.Start();

It DOES successfully start the application. The original Forms
Application must WAIT on the other program, so I added the following
line:

_proc.WaitForExit();

When it executes that line, I get an Exception "No process is
associated with this object".

If I execute an old VB6 application instead of the ClickOnce
application, _proc contains valid information and the WaitForExit works
fine. What is the problem here?

One thing I have noticed is that the ClickOnce application only shows
up in Task Manager under the Processes window, not the Application
window. I also tried adding a call to Process.GetProcesses() to see
all the processes on the system. I do NOT see that process in the
array returned. Should I see a process with the name of App1.exe?

Thanks for the help,

Chris
 
C

Chris

Today I put in a Thread.Sleep(xxx) call before I go get the processes
with GetProcesses() and it is finding my App1 process. I would still
prefer to just be able to do a _proc.WaitForExit() right after I do the
_proc.Start(), but that isn't working.

If someone knows why, I would still like an answer.

Thanks,

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top