I am trying to open simple .net exe/notepad.exe using process.start in hidden mode. and I need the process handle later to make the application.exe to make it visible after some time.
Able to get handle only in WindowStyle.Minimized, WindowStyle.Maximized, WindowStyle.Normal. In Hidden style, it gives me 0 always.
How to get handle without using Thread.Sleep. It requires us to wait few seconds, to get handle. some exe requires more wait time, based on its performance(huge data).
public static void LaunchExe() { var proc = new Process { StartInfo = { FileName = "Notepad.exe", //or any simple .net exe WindowStyle = ProcessWindowStyle.Hidden } }; proc.Start(); proc.WaitForInputIdle(800); //is it possible to avoid this. Thread.Sleep(3000); //is it possible to avoid this. Console.WriteLine("handle {0}", proc.MainWindowHandle); //ShowWindowAsync(proc.MainWindowHandle, 1); //planned to use, to make it visible. }