G
Gnanaprakash Rathinam
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.
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.