MRu
MRu

Reputation: 1395

Launch and pass arguments to another project

This maybe a silly question. But I'm really stuck on this one.

How can i launch and pass arguments from one project to another project? Lets say I have AppA and AppB. And from AppA I want to launch and send arguments to AppB.

How can I launch AppB and receive the arguments in static void Main(string[] args)?

namespace AppA
{
    class StartProgram
    {
        static void Main(string[] args)
        {
            argsOne = args[0].ToString();
            argsTwo  = args[1].ToString();
            argsThree = Convert.ToBoolean(args[2].ToString());
            argsFour = Convert.ToBoolean(args[3].ToString());
            argsFive = Convert.ToBoolean(args[4].ToString());

            //code to pass to another project in Main with arguments
        }
    }
}

Another project in the same solution:

namespace AppB
{
    class ETL
    {
        static void Main(string[] args)
        {
            argsOne = args[0].ToString();
            argsTwo  = args[1].ToString();
            argsThree = Convert.ToBoolean(args[2].ToString());
            argsFour = Convert.ToBoolean(args[3].ToString());
            argsFive = Convert.ToBoolean(args[4].ToString());     
        }
    }
}

Upvotes: 2

Views: 456

Answers (1)

VinothNair
VinothNair

Reputation: 634

Try this. Note : I have not tested this code.

using System.Diagnostics;
        namespace AppA
        {
            class StartProgram
            {
                static void Main(string[] args)
                {
                    ProcessStartInfo startInfo = new ProcessStartInfo("AppB.exe"); //you can allso provide full path of the exe if both these exe's are not present on the same folder
                    startInfo.WindowStyle = ProcessWindowStyle.Minimized;

                    Process.Start(startInfo);

                    startInfo.Arguments = string.Join(" ",args);

                    Process.Start(startInfo);
                }
            }
        }

Upvotes: 1

Related Questions