all groups > dotnet academic > december 2004 >
You're in the

dotnet academic

group:

CreateInstranceAndUnwrap slow perfomance


Re: CreateInstranceAndUnwrap slow perfomance Mujtaba Syed
12/29/2004 11:37:55 AM
dotnet academic:
Hi:

[quoted text, click to view]

How much time?
You are using late binding and that too across AppDomains. It's definitely
not going to be as fast as a new ().

Mujtaba.




CreateInstranceAndUnwrap slow perfomance Gnanaprakash Rathinam
12/29/2004 5:57:47 PM
Hi Expert,

We are trying to create an object in secondary appdomain from default
appdomain using CreateInstanceAndUnwrap api, But this call seems to be
taking lot of time to return, I know the call involve loading of required
assembly of the class/type and create object of type and return the proxy
object to the default domain. But I look for any other alternative way of
doing this???


// Sample c# code
class Test
{

static void Main()
{
CreateInstanceInSecondaryAppdomain(); // OK!
}

static void CreateInstanceInSecondaryAppdomain()
{
try
{

// Create a new AppDomain.
AppDomain ad =
AppDomain.CreateDomain("SecondaryAppDomain");


MarshalByRefType instance = (MarshalByRefType)
ad.CreateInstanceAndUnwrap(
Assembly.GetCallingAssembly().FullName,
"CreateInstanceAndUnWrap.MarshalByRefType",
true,
BindingFlags.Default,
null,
null,
null,
null,
null
);

// I'm done using the other AppDomain, so
// I'll unload it and all its assemblies.
AppDomain.Unload(ad);
}
catch (TypeLoadException e)
{
Console.WriteLine(e.Message);
}
}
}

class MarshalByRefType : MarshalByRefObject
{
//System.Runtime.Remoting.Activation.IActivator.
// This instance method can be called via a proxy.

public MarshalByRefType()
{
}
public void SomeMethod(String sourceAppDomain)
{
// Display the name of the calling AppDomain and my AppDomain.
// NOTE: The application's thread has transitioned between
AppDomains.
Console.WriteLine(
"Code from the '{0}' AppDomain\n" +
"called into the '{1}' AppDomain.",
sourceAppDomain,
Thread.GetDomain().FriendlyName);
}
}

Thanks,
GP.

AddThis Social Bookmark Button