Link to home
Start Free TrialLog in
Avatar of jackjohnson44
jackjohnson44

asked on

c# pass command line arguments to open application or open new instance

I made two sample programs.  One accepts command line arguments, the other uses a mutex to close itself if there is another instance open.  I was hoping to combine them so that I can pass command line arguments to the open app.  currently, using the mutex, I can only close the extra instance.

//I use this to accept command line arguments
        static void Main(string[] args)


//I was using this to see if I had another instance open, and close itself
            bool success;
            Mutex mut;
            mut = new Mutex(true, "MyUniqueName", out success);
            if (success)
            {
                // Application ok to start
            }
            else
            {
                // Application not ok to start
                Application.Exit();
            }
            // Prevent garbage collector getting rid of your mutex object...
            GC.KeepAlive(mut);
Avatar of ZachSmith
ZachSmith
Flag of United States of America image

You want to send arguments to the currently open application from the new application that was opened?
ASKER CERTIFIED SOLUTION
Avatar of ZachSmith
ZachSmith
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jackjohnson44
jackjohnson44

ASKER

I am not necessarily saying that I want to send the arguments from the newly opened project, just from the command line.  If it is forced to go throught the open project, that is fine.  I really don't care how, the main issue is one application and passing command line arguments to it.
I must not be understanding you right. If the application is already open then you cannot send command line arguments to it. That is why I posted the IPC link.
thanks, you are understanding me right.  I just wanted to make sure the object was to send command line arguments to an open app, if it has to go through another project that is fine.  I didn't want to pigeon hole myself in to a solution based on my not understanding all my options.  If you can't send them through the comand line, then through the open project is the way to go.  I will take a look at the link.
Yeah, command line arguments are only populated when the application starts. So if you need to communicate some data to an open application you'll have to use a different approach - such as the IPC link I posted.