Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have an application - APP1.
It has public classes, properties, methods etc. and it does a lot of work to load and display and therefore has a splash form.
I also create a number of controls created at runtime, and therefore there is quite a bit of code before the main InitializeComponent() in Sub New().
APP1 also reads a lot of data, which it organises and stores in collections etc.

I have a second application - APP2.
APP2 uses some of the classes in APP1.
I would like APP2 to be able to use the data in APP1 without having to re-read all the data previously read by APP1.
APP2 has a reference to APP1 so it undertstands the APP1 object model.
Also APP1 is visible and the user may well change some of the data which APP2 needs to know about.

If I use the code in APP2: Dim app as New APP1; then a second instance of APP1 loads, displays the Splash screen etc.

I then thought I might use COM. ie
APP2 would have a GetObject(,"APP1") but I get an error - Can't Create ActiveX etc.

Any ideas which way to go??

I am using VB in the 3.5Framework
Posted
Updated 5-May-11 2:26am
v2
Comments
willempipi 5-May-11 8:39am    
I'm sorry but I don't really understand why you would like to create something like this, can't you just make 1 application with 2 forms, then create a eventhandler on both forms and subscribe form1 to form2, and vice versa.
Sergey Alexandrovich Kryukov 6-May-11 9:26am    
The problem is pluggability, in fact.
I posted a comprehensive solution, please see.
--SA
Stuart Nathan 5-May-11 12:27pm    
Yes you are correct, but APP1 would really like to access AutoCad, but AutoCad comes in many versions. People do not automatically upgrade to the latest release because it is so expensive. Although it is now R2012, many are still using R2000.
So I thought that APP2 could deal simply with AutoCad, and be recompiled for the various different flavours. Which APP2 I use is still something in the future.

You could set up a WCF channel between the two, and transfer the data that way (probably when app2 starts up, it would initiate the transfer).
 
Share this answer
 
v2
Comments
Hemant__Sharma 5-May-11 8:51am    
yes WCF channel.. right. My 5
Stuart Nathan 5-May-11 12:24pm    
I had never heard of WCF so I looked it up and I believe WCF is new to Framework 4.
I am using 3.5
Dave Kreskowiak 5-May-11 18:41pm    
No, it's not. WCF came out as an extension in .NET 3.0.

Read -> http://msdn.microsoft.com/en-us/netframework/aa663324
Sergey Alexandrovich Kryukov 5-May-11 18:51pm    
That can probably work for OP (my 5), but most likely OP does not need it at all.
Please see my answer.
--SA
Sergey Alexandrovich Kryukov 6-May-11 11:14am    
John, this would work but makes no sense. Please see my solution.
--SA
Do you have source code for both applications? If you do, re-work them to run in one process. Of course, you could and usually should to segregate code in different assemblies, but use them as libraries, not different applications.

[EDIT]

So, you goal is not having two applications and communication. You goal is make a part of the code pluggable. This is reasonable. No way it should be two different applications and different processes!
Having part of the code pluggable does not mean different process, it's rather the opposite. You need to make pluggable code a separate assembly and pluggable during run-time, in the very beginning of it.

Make a plug-in interface, implement in it for two or different version of AutoCAD (or whatever else). Have a configuration file to specify which DLL to use, load appropriately selected assembly during run time and invoke the instance of the code implementing you plug-in interface. Having it all in one process is very important.

Now, you will find a very detailed sketch of plug-in architecture here:
Create WPF Application that uses Reloadable Plugins...[^],
AppDomain refuses to load an assembly[^].

Now, don't get it wrong! Most of the text in the above solutions is devoted to the difficult problem of re-loaded plug-ins. You don't need anything re-loadable. So you should ignore anything related to Application Domains and the discussion of really difficult problems or unloading/reloading. You architecture will be really simple. Just read on how to develop the plug-in architecture, loading of the assembly, recognition of the plug-in implementation in the loaded assembly and invocation of the class implementing plug-in.

Please, do yourself a favor: stop playing with the idea of separate processes. It's possible, will require ICP, remoting would be just an evil in your case. Don't do it, do plug-ins.

—SA
 
Share this answer
 
v2
Comments
Stuart Nathan 6-May-11 3:54am    
Please see my comment to Willempipi
Sergey Alexandrovich Kryukov 6-May-11 9:27am    
I put forward a complete solution.
--SA
Stuart Nathan 6-May-11 11:16am    
I have had a look at your solution above, and it is too complicated for me to understand. My own experience is to program simply. (I am not a professional programmer).
As I wrote earlier, I am trying to talk to AutoCad of which there are many releases with varying object models etc.
I have two problems.
The first is to attach my application to AutoCad and to run an application loaded into Autocad. I am using GetObject and CreateObject to do so (with some difficulty - I don't know why), but I could use late binding and define an Object. As long as I can send a message to Autocad to execute the internal application.
The second problem is to write an application (APP2) that can be independant of APP1. I have decided thanks to your posts, to revert to what I used to do which is to write and read files or the Windows Registry to communicate. (There is not much data required to pass).
The second problem will need recompiling for every version of Acad. But loading the correct version is simple, as AutoCad looks at the windows registry to see what additional apps it needs to load.

Reading the posts, it seems to me that there is a whole discussion to be had about whether keeping solutions simple or using the latest technology. My own view is not to trust technologies I don't fully understand or (more importantly) control. What if Microsoft decide not to support or change a technology?

It would be nice to know your views.
Sergey Alexandrovich Kryukov 6-May-11 11:37am    
1) Believe me, dealing with different processes will give you a lot more trouble.
2) My solution for you is really very simple. The problem is my past answer: most of the text is devoted to much more complex cases you don't need to consider. What is relevant to your case is really a few lines.
--SA
Stuart Nathan 6-May-11 11:18am    
I should explain that Autocad only loads external apps. It does not automatically execute them.

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