views:

209

answers:

4

Hi, is it possible to transfer a object from one application to another (in C#)?

I'm working with a CAD API. The initialization of that API takes a few seconds (10 - 15). Would be nice if I could initialize the object only once in App1 and call it up from App2 whenever I need it.

Any ideas? Thanks!

+6  A: 

You can do this by Serializing your object, and using any form of Interprocess Communication to transmit the data, then deserializing it on the other end.

Windows Communication Foundation is specifically suited to this type of scenario, and handles most of the plumbing for you.

Reed Copsey
+1 for links and well thought answer
george9170
Thanks a lot for your answer. Will study that :-)
iDog
+1  A: 

While Reed's suggestion is perfectly good one, it may not be the only possibility worth considering. 10-15 seconds initializing is quite a long time. It may be initializing some fairly large, complex data structures that could take quite a while to serialize and deserialize. If so, it might be worth considering another possibility, such as creating an out-of-process COM (or DCOM) server that acts as a front-end for the CAD API, and then let both App1 and App2 work with that server in one place. This would mean marshalling and unmarshalling all the data you send to/receive from the CAD API, but depending on how much data is involved and (particularly) how often you'd need to switch from its being used by App1 vs. App2, it might still have lower overhead.

Jerry Coffin
"It may be initializing some fairly large, complex data structures that could take quite a while to serialize and deserialize." -----Yes that's what I was worrying about too. Since serializing and deserializing might also take 10 seconds. But I'll give a try.
iDog
+1  A: 

An even simpler possibility, in my view, is to use shared memory. This is a common mechanism for interprocess communication under Windows. You may want to take a look at the linked CodeProject article.

Phileosophos
Thank you for the link!
iDog
A: 

in my idea using delegate is the best way for passing data between two form

Arash Afshinfar