Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello guys, I already have a project created and consolidated, and I'm creating another project. I need to call the second project from the first one, passing a parameter, and the actions I do in the second project must be passed on to the first one.

Example. Project A calls Project B... waits for the user to close B, and whatever the user enters into B's textbox, it will return to project A.


What I have tried:

Project A
private void button1_Click(object sender, EventArgs e)
        {
            
            string cPath = @"C:\Users\test";
            string filename = Path.Combine(cPath, "WinFormsApp3.exe");
            var proc = System.Diagnostics.Process.Start(filename, textBox1.Text, null, null, null);
            proc.CloseMainWindow();
            proc.Close();
        }


Project B

static void Main(string test)
        {
            if (string.IsNullOrWhiteSpace(test))
            {
                string arg1 = test;

                Application.SetHighDpiMode(HighDpiMode.SystemAware);
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Project2(arg1));
            }
            else
            {
                Application.SetHighDpiMode(HighDpiMode.SystemAware);
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Project2());
            }
        }
Posted
Updated 20-Oct-21 0:44am
Comments
BillWoodruff 19-Oct-21 11:58am    
"the actions I do in the second project must be passed on to the first one."

is having two processes (.exe) running a requirement /

In project B you can use the Program class Main(string[] args) method for this.
See: https://www.dotnetperls.com/main[^]
The examples are for a console application, but you can use this for a forms application too.
 
Share this answer
 
v2
Comments
BillWoodruff 20-Oct-21 6:37am    
OP: "actions I do in the second project must be passed on to the first one."

Your answer is good, but it doesn't address the two-way interaction between processes the OP describes. Of course, that is a very advanced topic !
RickZeeland 20-Oct-21 12:34pm    
That's right, I did not want to mention named pipes and stuff like that :)
BillWoodruff 20-Oct-21 12:41pm    
i respect that choice :)
"actions I do in the second project must be passed on to the first one."

Two-way interaction between processes (IPC) is a very advanced topic ! [^], and will take time and effort to implement.

Also see: [^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900