DLL is dynamically loaded in. NET and released in time after the call.

Source: Internet
Author: User
Problem:

In many cases, we want to dynamically loadProgramTo release the loaded DLL file in time to release resources and update DLL files.

Solution:

Currently, CLR does not provide a method to uninstall an assembly. While assembly is resident in appdomain, appdomain can be dynamically detached and created.

For example, there is a dynamically generated Class Library:

Public   Class Helloworld: Export albyrefobject

{
Public Helloworld ()
{

}

Public   Void Task1 ( String S)
{
Console. writeline ("Task1" +S );
}
}

Dynamic call // File: invoke. CS

Using System;
Using System. reflection;
Using System. runtime. remoting;



Public   Class Invokemethod
{

Public   Static   Void Main (string [] argv)

{

Appdomainsetup info =   New Appdomainsetup ();
Info. applicationbase =   " File :/// "   + System. environment. currentdirectory;
Appdomain dom = Appdomain. createdomain ( " Remotedomain " , Null , Info );
Assembly ASM = Assembly. Load ( " Helloworld2 " );
Object OBJ = ASM. createinstance ( " Helloworld " );
Methodinfo minfo = ASM. GetType ( " Helloworld " ). Getmethod ( " Task1 " );
Minfo. Invoke (OBJ, New   String [] {"Task 1"} );
Appdomain. Unload (DOM );

}

}

Restrictions:
The DLL to be dynamically loaded must be in the same directory as the host.

Refer:

Http://www.gotdotnet.com/team/clr/AppdomainFAQ.aspx#_Toc514058481

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.