• 0

[.NET] AppDomain "concatenator"


Question

I'm writing a small piece of code that's responsible to cause each application using it to start up in the same application domain in the initial process space.

What it's basically doing is to check if an application with same code runs already, and if it does, the application, that starts up, notifies the first one to take over the start by using a seperate AppDomain in its process space. After the start notification has been handed over, the second application stops and the first one starts it in its own process space. (An AppDomain is a lightweight "process", one process can host multiple AppDomains.)

Anyone needs such thing? If so, please say so, so that I'll write a clean version. I've got the basic plumbing done atm.

A scenario might be where you've an application suite, but want it to be as lightweight as possible, e.g. by running everything in the same process. Process priority adjustments are planned too.

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

I do need a part of this though.

I need a simple class which will create a new AppDomain,

loads a dll library, Lets me call functions in the dll

and once I done with the dll, unloads the AppDomain.

All the dlls that I load share the same interface but have different implementations

I had been planning to write this class for a long time but never got to it.

I need it for my AI program which currently runs out of memory because the loaded dlls are not unloaded until the application is closed.

Link to comment
Share on other sites

  • 0

Evidence parentEvidence = Assembly.GetExecutingAssembly().Evidence;
Evidence evAppDomain = new Evidence(parentEvidence);
Evidence evAssembly = new Evidence(parentEvidence);
AppDomain appDomain = AppDomain.CreateDomain("Glueball" + (new Random().Next()).ToString(),
        evAppDomain, basePath, string.Empty, false);

Assembly loadedAssembly = appDomain.Load(assemblyName, evAssembly);
Type yourType = loadedAssembly.GetType(...);
YourUnfoldedType wootWoot = Activator.CreateInstance(yourType) as YourUnfoldedType;

wootWoot.SomeFunction();

Cut'n'paste ninjaing! It's something like that.

The classes you want to access cross AppDomains need to be derived from System.MarshalByRefObject btw.

--edit: Wait, I almost forgot, "assemblyName" is the fullname of the assembly, not the filename. You can however feed a byte[] array that contains the assembly code.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.