Using Visual Studio Version 17.12.3
C# Winforms with .Net Framework 4.8.1
I am building the installation process for my application. In this particular situation, I need to spawn a process to run the installer for the database provider based on the user's selection. I would like to have the shelled application complete and return cotrol to the install process.
I followed the document "Use Visual C# to wait for a shelled application to finish" on the Microsoft site. What I am experiencing is the line p.WaitForExit() does not wait, the code will continue. I have tried placing a wait value of varying size with no affect.
This is the first time I have tried this and not quite sure if I am doing the right thing oe is there a better way to accomplish this.
Here is the code snip in question. This is enclosed in a Try/Catch.
string sysFolder = Environment.GetFolderPath(Environment.SpecialFolder.System); ProcessStartInfo pInfo = new ProcessStartInfo(); pInfo.FileName = sysFolder + @"\notepad.exe"; Process p = Process.Start(pInfo); p.WaitForInputIdle(); p.WaitForExit(); if (p.HasExited == false) { p.WaitForExit(5000); } return p.ExitCode == 0;