Description



Description

[Note: An AssemblyLoadEventHandler instance is used to specify the methods that are invoked in response to an AppDomain.AssemblyLoad event. To associate an instance of AssemblyLoadEventHandler with an event, add the instance to the event. The methods referenced by the AssemblyLoadEventHandler instance are invoked whenever an assembly is loaded, until the AssemblyLoadEventHandler instance is removed from the event. For additional information about events, see Partitions I and II of the CLI Specification.]

Example

using System;





public class AssemblyLoadEventHandlerSample

{

    public static void Main()

    {

        AppDomain domain = AppDomain.CreateDomain("MyNewDomain");

        domain.AssemblyLoad +=

            new AssemblyLoadEventHandler(MyLoadHandler);

        Console.WriteLine("Attempting to execute HelloWorld.exe...");

        domain.ExecuteAssembly("HelloWorld.exe");

        Console.WriteLine("Finished executing HelloWorld.exe.");

        Console.WriteLine();

        Console.WriteLine();

        Console.WriteLine("Press Enter to continue");

        Console.ReadLine();

    }



    public static void MyLoadHandler(object sender,

        AssemblyLoadEventArgs args)

    {

        Console.WriteLine("Loaded assembly {0}",

            args.LoadedAssembly.FullName);

    }



}


The output is


Attempting to execute HelloWorld.exe...

Loaded assembly HelloWorld, Version=1.0.1767.19756, Culture=neutral, PublicKeyTo

ken=null

Loaded assembly System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, Publi

cKeyToken=b77a5c561934e089

Loaded assembly System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a

5c561934e089

Loaded assembly System.Drawing, Version=1.0.5000.0, Culture=neutral, PublicKeyTo

ken=b03f5f7f11d50a3a

Loaded assembly System.Xml, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=

b77a5c561934e089

Finished executing HelloWorld.exe.





Press Enter to continue