0

I developed a c# single instance application. I want to pass the command line arguments of the second instance to the already running instance before the second instance kills itself. Is there any simple way to do this ?

Wesley Lomax
  • 2,067
  • 2
  • 20
  • 34
Unknown
  • 73
  • 8
  • Possibly related question: http://stackoverflow.com/questions/2613161/how-to-write-to-the-stdin-of-another-app – Codor Sep 24 '15 at 13:18
  • 2
    You have a single instance application that runs with 2 instances? – rmn36 Sep 24 '15 at 13:18
  • 2
    The Windows Communication Framework is easier to implement than it seems and is great for interprocess-communication. – Jens Sep 24 '15 at 13:18
  • 2
    @rmn36 No. When the user tries to open another instance that will make the running instance to open and kills itself – Unknown Sep 24 '15 at 13:22
  • [A truly simple WCF sample](http://weblogs.asp.net/ralfw/a-truely-simple-example-to-get-started-with-wcf) <-- Read this – Matthew Watson Sep 24 '15 at 13:31
  • Does it need to be a separate app? Could you not just use a .dll? – Krythic Sep 24 '15 at 13:38
  • @Krythic it needs to be a separate app. – Unknown Sep 24 '15 at 13:42
  • @Unknown Care to explain why? I am having trouble justifying this in my mind. A dll could serve the exact same purpose as what you have described. Perhaps you should restructure your project. – Krythic Sep 24 '15 at 13:44
  • @Krythic: huh? It's an application, so it needs to be an application. How do you expect the user to run a DLL? – Harry Johnston Sep 24 '15 at 23:03
  • @HarryJohnston I don't. I expect you to interface it. – Krythic Sep 24 '15 at 23:04
  • 1
    @Krythic: that doesn't make sense, so far as I can see. It's an application. The user wants to run it, not "interface" it. DLLs are for situations where two separate applications want to share the same code, but in this case there is only one application. – Harry Johnston Sep 24 '15 at 23:22
  • @HarryJohnston No...there is two. You said that yourself. Look, I tried to help you. You can still execute tasks from a .dll. And the fact that you failed to explain why you could not use one, leads me to believe that you have no idea what you're doing. I will take my leave now; have a great day and I hope your project finds its completion. – Krythic Sep 24 '15 at 23:26
  • 1
    @Krythic: are you confusing me with the OP? At any rate, there is only one application. There are two *instances* of that application. Two processes, both running the same application, not two separate applications. The newer process needs to pass the command line to the older process and exit. (That's what "single-instance application" means; an application that only permits one instance of itself to run at a time.) – Harry Johnston Sep 24 '15 at 23:31

1 Answers1

3

There's so many ways to do this, IMHO.

A quick and dirty way would be to anonymous pipes. Just before you quit the second instance, you could make a call over the pipes, passing the command line args (maybe do a string.Join(new []{','}, args) to concatenate them first).

There's so many other ways to do inter-process communications though.

A very simplistic example of anonymous pipes usage is give on MSDN: https://msdn.microsoft.com/en-us/library/bb546102(v=vs.110).aspx

HTH.

code4life
  • 15,655
  • 7
  • 50
  • 82