Process.HasExited and Process.WaitForExit() in C#
-
I've got a serious problem with these two. In short, they aren't working or I'm not doing it right (I'm hoping it's the latter). I am trying to open a Word document. After the user closes the Word document, I want to start another process (namely, a web address). Every time, the processes open one after the other -- without pausing or anything. Here is the code I have (and I have tried various rearrangements):
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(); psi.RedirectStandardOutput = true; psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized; psi.UseShellExecute = false; psi.Arguments = @txt_Wordfile.Text; psi.FileName = @WordExe]; System.Diagnostics.Process WordProcess = new System.Diagnostics.Process(); WordProcess = System.Diagnostics.Process.Start(psi); WordProcess.EnableRaisingEvents = true; WordProcess.WaitForExit(); System.Diagnostics.Process.Start(txt_website.Text);
Even in debug mode, it shows WordProcess.HasExited == true right after the process starts. Also, the window does not open maximized. Please help! Thanks! -
I've got a serious problem with these two. In short, they aren't working or I'm not doing it right (I'm hoping it's the latter). I am trying to open a Word document. After the user closes the Word document, I want to start another process (namely, a web address). Every time, the processes open one after the other -- without pausing or anything. Here is the code I have (and I have tried various rearrangements):
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(); psi.RedirectStandardOutput = true; psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized; psi.UseShellExecute = false; psi.Arguments = @txt_Wordfile.Text; psi.FileName = @WordExe]; System.Diagnostics.Process WordProcess = new System.Diagnostics.Process(); WordProcess = System.Diagnostics.Process.Start(psi); WordProcess.EnableRaisingEvents = true; WordProcess.WaitForExit(); System.Diagnostics.Process.Start(txt_website.Text);
Even in debug mode, it shows WordProcess.HasExited == true right after the process starts. Also, the window does not open maximized. Please help! Thanks!I think that this is due to the fact that Word starts up by opening an intermediary executable, which is killed immediately after it loads the actual Word executable. What you should probably do is use the windows handle to call the win api method ShowWindow to maximize after you instantiate word (look for windows with class name "OpusApp"). Hope this helps,
Sounds like somebody's got a case of the Mondays -Jeff
-
I think that this is due to the fact that Word starts up by opening an intermediary executable, which is killed immediately after it loads the actual Word executable. What you should probably do is use the windows handle to call the win api method ShowWindow to maximize after you instantiate word (look for windows with class name "OpusApp"). Hope this helps,
Sounds like somebody's got a case of the Mondays -Jeff
I think I know what you're talking about, but just in case I'm wrong, could you put that in a sample code? Thanks!