AppDomain scopes
-
Hi buddies, Suppose we have created an AppDomain with FriendlyName "NewDomain" in the current AppDomain named "CurrentDomain" and have created an instance of class A in that, now we call some method of that instance, Here is the code: AppDomainSetup domainSetup = new AppDomainSetup(); domainSetup.ApplicationBase = @"c:\myApp"; domainSetup.ShadowCopyDirectories = @"c:\myApp"; domainSetup.LoaderOptimization = LoaderOptimization.SingleDomain; AppDomain appDomain = AppDomain.CreateDomain("NewDomain", null, domainSetup); // Here the constructor is called in the 'NewDomain' domain A obj = (A)appDomain.CreateInstanceAndUnwrap(assemblyName, "A"); // Here the 'MyMethod' is called in the current application domain obj.MyMethod(); While tracing "AppDomain.CurrentDomain.FriendlyName" in class A, I see: 1. In its constructor scope, it is "NewDomain", that is ok 2. In the called method scope, it is "CurrentDomain". It means that the method is called in the 'CurrentDomain', while I wana the method be called in the "NewDomain" application domain. How can I perform it ? Thanks --- "Art happens when you least expect it."
-
Hi buddies, Suppose we have created an AppDomain with FriendlyName "NewDomain" in the current AppDomain named "CurrentDomain" and have created an instance of class A in that, now we call some method of that instance, Here is the code: AppDomainSetup domainSetup = new AppDomainSetup(); domainSetup.ApplicationBase = @"c:\myApp"; domainSetup.ShadowCopyDirectories = @"c:\myApp"; domainSetup.LoaderOptimization = LoaderOptimization.SingleDomain; AppDomain appDomain = AppDomain.CreateDomain("NewDomain", null, domainSetup); // Here the constructor is called in the 'NewDomain' domain A obj = (A)appDomain.CreateInstanceAndUnwrap(assemblyName, "A"); // Here the 'MyMethod' is called in the current application domain obj.MyMethod(); While tracing "AppDomain.CurrentDomain.FriendlyName" in class A, I see: 1. In its constructor scope, it is "NewDomain", that is ok 2. In the called method scope, it is "CurrentDomain". It means that the method is called in the 'CurrentDomain', while I wana the method be called in the "NewDomain" application domain. How can I perform it ? Thanks --- "Art happens when you least expect it."
Make sure that A derives from MarshalByRefObject and isn't just serializable.
I can imagine the sinking feeling one would have after ordering my book, only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
-
Make sure that A derives from MarshalByRefObject and isn't just serializable.
I can imagine the sinking feeling one would have after ordering my book, only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon