-
Process.WaitforExit
Has anyone had any success using this?
I have the following code
Code:
try
{
//Here we just need to shell the Dirver installation
Process Proc = new Process();
//I dont need to know when we are done
Proc.EnableRaisingEvents=false;
//Get it set up
Proc.StartInfo.Arguments = "REDISTRIBUTION RESPONSEFILE=\"" +
Environment.CurrentDirectory.ToString() + "\\Drivers\\response.txt\"" ;
Proc.StartInfo.FileName = Environment.CurrentDirectory.ToString()
+ "\\Drivers\\redist.exe";
//Launch install
Proc.Start();
Proc.WaitForExit();
}
catch ( System.ComponentModel.Win32Exception )
{
//If we come in here, we had an error
MessageBox.Show(this,"Main Menu could not find the " +
"video card driver setup file. Please " +
"check to ensure the CD is installed " +
"in the CD-ROM.","Error Reading CD",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
It hangs will not always launch my app. If it does launch the app, then when the new process exits, it does not restore itself and hangs up.
Thanks for your help,
Jerel
-
what are you trying to acomplish? you are not doing nothing after the other app gives focus again to your app
-
This code is duplicated a few times in the program, not the best program layout but I took it out here for somereason when I pasted it.
After the process I spawn ends, I either need to reboot the computer or launch the program manual which happens to be in adobe.
So in one part of the program, I try to launch a program manual, if I dont detect adobe, I spawn the adobe install, I want to wait until the intstall is complete, then spawn the manual.
Does that make sense?
Jerel
-
yes but what are you doing after
Proc.Start();
Proc.WaitForExit();
?
-
I dont have anything after them, do I have to have something after the waitforexit for it to operate correctly?
The main point for having them wait is, this app is a main menu for a CD. It autoruns and the user can install the program, adobe, or some video card drivers. I dont want them to choose more than one option and also I need to reboot after they install the drivers.
So there are three places where I wait, It could be more efficient I know, just trying to get it all to work first. One of the place, which is what I posted here, needs to rebot the machine. I have not written that code yet.
-
This fixed the problem. I added one line WaitForIdleInput.
This line will wait until the given process is waiting for user input with no input pending, per the definition. I actually noticed when you launch older versions of InstallShield, especially Adobe, if I did not add this line, the shelling of the program would hang at 99%. Not sure what the installer is doing, but adding this line fixed the problem.
Code:
try
{
//Here we just need to shell the Dirver installation
Process Proc = new Process();
//I dont need to know when we are done
Proc.EnableRaisingEvents=false;
//Get it set up
Proc.StartInfo.Arguments = "REDISTRIBUTION RESPONSEFILE=\"" +
Environment.CurrentDirectory.ToString() + "\\Drivers\\response.txt\"" ;
Proc.StartInfo.FileName = Environment.CurrentDirectory.ToString()
+ "\\Drivers\\redist.exe";
//Launch install
Proc.Start();
Proc.WaitForIdleInput();
Proc.WaitForExit();
}
catch ( System.ComponentModel.Win32Exception )
{
//If we come in here, we had an error
MessageBox.Show(this,"Main Menu could not find the " +
"video card driver setup file. Please " +
"check to ensure the CD is installed " +
"in the CD-ROM.","Error Reading CD",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
Jerel