开发者

How to load an assembly into different AppDomain on Windows Mobile (.NET CF)?

开发者 https://www.devze.com 2022-12-16 23:19 出处:网络
How to load an assembly into different AppDomain on Windows Mobile (.NET CF) for 开发者_如何学Pythonsubsequent AppDomain unload ?AppDomain.Load is not available in CF.NET, but you can try executing an

How to load an assembly into different AppDomain on Windows Mobile (.NET CF) for 开发者_如何学Pythonsubsequent AppDomain unload ?


AppDomain.Load is not available in CF.NET, but you can try executing an assembly. Keep in mind, that assembly needs to have a Main method.

AppDomain newDomain = AppDomain.CreateDomain("newDomain");      
newDomain.ExecuteAssembly("Application.exe");


Try something like this:

class ServiceApplicationProxy : MarshalByRefObject
{
    public void Configure()
    {
        Assembly serviceAssembly = Assembly.Load(new AssemblyName()
        {
            CodeBase = @"c:\fullpath\assembly.dll")
        });
        // do something
    }
}

class Class1
{
    public void Start()
    {
        Type activator = typeof(ServiceApplicationProxy);
        AppDomain domain = AppDomain.CreateDomain(
            "friendlyName", null, new AppDomainSetup());
        ServiceApplicationProxy proxy =
            domain.CreateInstanceAndUnwrap(
                Assembly.GetAssembly(activator).FullName,
                activator.ToString()) as ServiceApplicationProxy;

        Console.WriteLine("Press ENTER to exit");
        Console.ReadLine();
        AppDomain.Unload(domain);
    }
}

EDIT: From documentation at http://msdn.microsoft.com/en-us/library/system.appdomain(VS.71).aspx:

.NET Compact Framework Platform Note: The .NET Compact Framework does not support loading assemblies into a domain neutral code area for use by multiple application domains.

0

精彩评论

暂无评论...
验证码 换一张
取 消