3

I have 2 different C# programs, both of them contain a form application.

How can I run both these 2 programs in one of them?

I added, using the existing project option, progr1 in program 2.
Now I want to run program2.
When program 2 runs and it pops up the form application I want to also activate (automatically) program 1 and the form application from this project to also pop up.

I would also want to have access to all the methods from one program in the other one.

Thanks for your help.

Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
elisa
  • 743
  • 2
  • 13
  • 31

4 Answers4

3

If they are indeed separate processes, then you need to look at Inter Process Communication. There are a bunch of different options for doing this, personally, I'd look at WCF to talk in between applications.

But that assumes that these are separate processes. Another thing you might consider is just having one process that launches multiple windows. In this case, you can easily pass references to each window across and call methods and properties from the other one.

Joel Martinez
  • 46,929
  • 26
  • 130
  • 185
  • can you give me some examples? – elisa Mar 17 '11 at 12:06
  • i am refering to your second idea. If i have a process that lunches multiple windows how can i know on which of these windows i am working in a specifi time? – elisa Mar 17 '11 at 12:11
  • sure, just import all of your classes/forms/code into one project. And then from your main method, instantiate and call the form's "Show" method (http://msdn.microsoft.com/en-us/library/szcefbbd(VS.80).aspx). At this point, one of the easiest ways to enable cross form communication is to make each form a singleton (http://hashfactor.wordpress.com/2009/03/31/c-winforms-create-a-single-instance-form/). Of course, YMMV :-) – Joel Martinez Mar 17 '11 at 13:53
  • ok thx. the thing is that i do need 2 processes to run, not just the form application. i don't know how to access the form app from the existing project just using code. – elisa Mar 17 '11 at 14:30
  • i can;t use .exe. i need the methods, variable from the proj i've added in the curent one. – elisa Mar 17 '11 at 14:31
  • oh, then yes you are stuck with doing IPC. again, look into WCF ... of course this also assumes you have the source code and ability to modify both .exes – Joel Martinez Mar 17 '11 at 15:17
1

Most you can do is have one start the other using Process.Start but you won't be able to have access to methods of one in the other application.

There are many ways to communicate between processes, some of them are discussed here.

Community
  • 1
  • 1
Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
0

There are couple of options here provided you want to change the structure of Program1, which depends on your requirements and access to the applications.

  • Separate the Program1's form logic from main function and put it in a separate DLL

  • Refer the Program1's DLL in the Program2 and Control the form and its methods however you want.

Otherwise, Use Inter Process Communication techniques.

Kumar
  • 997
  • 5
  • 8
0

Perhaps you could consider running both of them in the same Application Domain.

http://msdn.microsoft.com/en-us/library/ms173138(v=vs.80).aspx

TheBoyan
  • 6,802
  • 3
  • 45
  • 61