0

Iam starting the wpf application by using the process.start ,my wpf application is visible in task manager,but not visible in the front end,its running as a back ground process,can some one help in bringing the wpf app visible.

ProcessStartInfo startInfo = new ProcessStartInfo(programFilesPath);
//ProcessStartInfo startInfo = new 
ProcessStartInfo("notepad.exe");
startInfo.WindowStyle = ProcessWindowStyle.Maximized;
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
Process p = Process.Start(startInfo);
  • 1
    Here is a very helpful link: https://stackoverflow.com/questions/33794377/start-wpf-application-in-console-application –  Jul 23 '19 at 09:22

1 Answers1

0

I think this may work :

[DllImport("user32")]
private static extern bool SetForegroundWindow(IntPtr hwnd);
public static void Processing(string WorkingDirectory, string FileName, string Arguments, bool StandardOutput, string OutputFileName)
    {
        Process proc = new Process();
        proc.EnableRaisingEvents = true;
        proc.StartInfo.UseShellExecute = false;
        proc.StartInfo.RedirectStandardOutput = StandardOutput;
        proc.StartInfo.FileName = FileName;
        proc.StartInfo.CreateNoWindow = true;
        proc.StartInfo.WorkingDirectory = WorkingDirectory;
        proc.StartInfo.Arguments = Arguments;
        proc.Start();
        //Added code
        System.Threading.Thread.Sleep(500);
        SetForegroundWindow(proc.MainWindowHandle);
        //........................................
        if (StandardOutput == true)
        {
            string output = proc.StandardOutput.ReadToEnd();
            DumpOutput(WorkingDirectory + "\\" + OutputFileName, output);
        }
        proc.WaitForExit();
        proc.Close();
    }
Bhushan Muttha
  • 420
  • 2
  • 11
  • i have tried the setforegroundwindow ,its working for any windows applicaton,but not working for wpf applications. – vamsi krishna Jul 23 '19 at 10:10
  • Have u tried to set the working directory to the path of the WPF application, rather than the working directory of the launching application `proc.StartInfo.WorkingDirectory = Path.GetDirectoryName(programPath);` Where var programPath = @"C:\Users\user\Documents\Program Directory\program.exe"; – Bhushan Muttha Jul 23 '19 at 10:35