Home All Groups Group Topic Archive Search About
Author
6 Feb 2006 9:29 PM
Joe
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

Author
7 Feb 2006 12:22 AM
AMercer
>  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
Are all your drivers up to date? click for free checkup

Author
7 Feb 2006 3:28 AM
Yuan Ren[MSFT]
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

Bookmark and Share