简体   繁体   中英

Start wpf application from console application

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);

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();
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM