AppDomain and threads

Basically, from what I understood about what I managed to find on the Internet, streams can go between AppDomains. Now I have written the following code:

const string ChildAppDomain = "BlahBlah"; static void Main() { if (AppDomain.CurrentDomain.FriendlyName != ChildAppDomain) { bool done = false; while (!done) { AppDomain mainApp = AppDomain.CreateDomain(ChildAppDomain, null, AppDomain.CurrentDomain.SetupInformation); try { mainApp.ExecuteAssembly(Path.GetFileName(Application.ExecutablePath)); } catch (Exception ex) { // [snip] } AppDomain.Unload(mainApp); } } else { // [snip] Rest of the program goes here } } 

This works great, and everything is clicked into place ... The main thread goes to the new version of my program and starts working through the main application body. My question is: how do I get it to return to the parent AppDomain ? Is it possible? What I'm trying to achieve is the exchange of a class instance between two domains.

+4
source share
2 answers

You cannot share class instances directly between AppDomain s. To do this, you must get the class from MarshalByRefObject and use remote access to access the instance from another AppDomain .

+8
source

An object in .Net can exist in only one AppDomain. It is impossible for it to exist in 2 applications at the same time.

However, you can use .Net Remoting to simultaneously push the .Net proxy object to multiple AppDomains applications. This will give your object an appearance in multiple domains. I believe that this is what you are looking for.

There are many tutorials available online. Google for the β€œ.Net Remoting Tutorial” and it will put you on the right track.

+1
source

All Articles