Home All Groups Group Topic Archive Search About

Run assembly method in another app domain

Author
5 Apr 2006 4:23 PM
nick_nw
Working with this example:

void foo ()
{

// Create the AppDomain
AppDomain newDomain = AppDomain.CreateDomain("newDomain", null, null);

TestNS.Test testInstance =
(TestNS.Test)newDomain.CreateInstanceFromAndUnwrap
(@"C:\Test\bin\Debug\Test.dll", "TestNS.Test");

// Call a test method in the object created
bool r = testInstance.Test ();

// Unload the appdomain
appDomain.Unload(newDomain);

}

Givent the above, when I call testInstance.Test () which appdomain will
it run in?  Will it run in the newDomain domain?

What I'm ultimately aiming to do is run the same assmebly code
concurrently in different app domains.  Is the above the right start?

In order to use the object returned by CreateInstanceFromAndUnwrap  I
had to add a reference to the DLL so that I had type information
available.  Could I achieve this without addinga reference, e.g.
through reflection?

P.S.  I wasn't sure which group to post in.  If this is no the best
group then apologies in advance.

Regards,

Nick

Author
6 Apr 2006 9:06 AM
Vadym Stetsyak
Hello, nick_nw!

nn> void foo ()
nn> {

nn> // Create the AppDomain
nn> AppDomain newDomain = AppDomain.CreateDomain("newDomain", null, null);

nn> TestNS.Test testInstance =
nn> (TestNS.Test)newDomain.CreateInstanceFromAndUnwrap
nn> (@"C:\Test\bin\Debug\Test.dll", "TestNS.Test");

nn> // Call a test method in the object created
nn> bool r = testInstance.Test ();

nn> // Unload the appdomain
nn> appDomain.Unload(newDomain);

nn> }

nn> Givent the above, when I call testInstance.Test () which appdomain will
nn> it run in?  Will it run in the newDomain domain?

Yes, testInstance is now transparent proxy.

nn> What I'm ultimately aiming to do is run the same assmebly code
nn> concurrently in different app domains.  Is the above the right start?

Generally yes. Why do need that? 

nn> In order to use the object returned by CreateInstanceFromAndUnwrap  I
nn> had to add a reference to the DLL so that I had type information
nn> available.  Could I achieve this without addinga reference, e.g.
nn> through reflection?

Yes, you have to know at least the name of the type, you want to create in separete domain

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Author
7 Apr 2006 7:32 PM
nick_nw
Hi.  Thanks for the reply.  In response to your questions and to
clarify things I've started a new post:
http://groups.google.co.uk/group/microsoft.public.dotnet.framework.interop/browse_thread/thread/19329f48cb02dece/b1fe32034a4b7a5a?hl=en#b1fe32034a4b7a5a

Many thanks,

Nick

AddThis Social Bookmark Button