2

How to run/invoke a WPF application (.exe) from a Windows Forms ? I know it can be done like shown below:

 Process.Start(@"C:\ABC\WPF.exe");

But I want to send few parameters to the WPF Applications from the winform application. How to do it ?

1
  • Process.Start() has some overloads. One of them allows to supply the arguments. Commented Apr 13, 2019 at 16:35

2 Answers 2

3

Refer to complete code from here

You can pass arguments from your winform app like

Process.Start(new ProcessStartInfo(@"C:\repos\WpfApp.exe", "Args from WinForms"));

and receive in WPF app like

public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            if (e.Args.Length > 0)
            {
                MessageBox.Show($"You have passed:{e.Args.Length} arguments," +
                    $" value are {string.Join( ",",e.Args)}");
            }
        }
    }
Sign up to request clarification or add additional context in comments.

3 Comments

I have 1 more doubt. The path of the wpf project exe cannot be hardcoded like this. We have a win form application [main application] and a wpf application. when running the winform application, at some point of time there is a need of invoking wpf application. at that time how we can speciy the path of the wpf application ?
place your WPF App binaries in a folder in same path of your WinForm App and use relative path. "./WPFApp/Wpfapp.exe"
@VikasGupta "./WPFApp/Wpfapp.exe" will not work. If you include the wpf binaries in the winform project, this should work: AppDomain.CurrentDomain.BaseDirectory + @"WPFApp\WpfApp.exe";
1

You can use the same method with a few parameters. So in your case

var procStart = System.Diagnostics.Process.Start(@"C:\ABC\WPF.exe", params);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.