Call a C# application from an existing C# application with ProcessStartInfo?

I have a solution that contains 2 projects:

xxxMode2 can be built as an independent desktop application. xxxTable project is a launcher. I will call xxxMode2 from xxxTable.

enter image description here

Here are 2 samples of code that I use to call the project xxxMode2 from the project xxxTable. Let's call them A and B.

        // Code A
        private void Button_Click_2(object sender, RoutedEventArgs e)
            Xxxxx.MainWindow mnw = new Xxxxx.MainWindow();
            mnw.Owner = this;
        // Code B
        private void Button_Click_2(object sender, RoutedEventArgs e)
            string currentFolder = Directory.GetCurrentDirectory();
            ProcessStartInfo pInfo = new ProcessStartInfo("");
            pInfo.WorkingDirectory = currentFolder;            
            Process p = Process.Start(pInfo);

In C#, what are the difference between calling a sub-project from a main-project between using the Classic way (code A) and the Process way (code B)?

I use this ProcessStartInfo() method when I want to launch an exe extern to my code. Is it correct, or make it sense, to do it from my main-project to my sub-project?

1 answer

  • answered 2021-07-27 07:20 66Gramms

    The difference is that when you go with the A method you have full control over that dialog. It is just going to be a window in the same process.

    With method B however, you are making a child process, which means you can't access the variables and other data of the program you just started with the Process class. This way you open a new process.

    You can still communicate with your program if you use method B, you can use the standard streams for that.

    If you can most of the time it is preferable to go with method A, if for some reason you can't then method B is fine. This is really depending on the project and what you want to achieve, but method A should be almost always the way to go.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum