I have a managed application called MainApp.exe and another non-managed
application called OtherApp.exe. I want to launch OtherApp.exe from
MainApp.exe using System.Diagnostics.Process.Start("OtherApp.exe"). This
works fine. Here is the trick: I want OtherApp.exe to behave like a modal
dialog. In other words, I don't want the user to be able to return to
MainApp.exe until OtherApp.exe has closed.
Is there any way to accomplish this?
Thanks,
Joe
AMercer - 07 Feb 2006 00:22 GMT
> In other words, I don't want the user to be able to return to
> MainApp.exe until OtherApp.exe has closed.
The logic I use for this is shown below. Otherapp will run without a new
console window, and mainapp reads otherapp's stdout. Trim this stuff out if
you want - the trick you need is p.WaitForExit().
Dim p As New System.Diagnostics.Process
Dim s As String
With p.StartInfo
.FileName = "otherapp.exe"
.Arguments = "whatever"
.UseShellExecute = False
.RedirectStandardError = True
.RedirectStandardInput = True
.RedirectStandardOutput = True
.WindowStyle = ProcessWindowStyle.Hidden
.CreateNoWindow = True
End With
Try
p.Start()
s = p.StandardOutput.ReadToEnd()
p.WaitForExit()
Catch ex As Exception
s = ex.ToString
End Try
"Yuan Ren[MSFT]" - 07 Feb 2006 03:28 GMT
Hi Joe,
Thanks for posting!
As AMercer mentioned, the Process.WaitForExit method is appropriate for the
current "trick". Just for your reference:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemDiagnosticsProcessClassWaitForExitTopic.asp
Regards,
Yuan Ren [MSFT]
Microsoft Online Support