Imports System.Reflection
Module Program
Sub Main()
Dim anotherAD As AppDomain = AppDomain.CreateDomain("SecondAppDomain")
' Load CarLibrary.dll into this new appdomain.
anotherAD.Load("CarLibrary")
' Hook into DomainUnload event.
AddHandler anotherAD.DomainUnload, AddressOf anotherAD_DomainUnload
' Now unload anotherAD.
AppDomain.Unload(anotherAD)
End Sub
Public Sub PrintAllAssembliesInAppDomain(ByVal ad As AppDomain)
Dim loadedAssemblies As Assembly() = ad.GetAssemblies()
Console.WriteLine(ad.FriendlyName)
For Each a As Assembly In loadedAssemblies
Console.WriteLine("-> Name: {0}", a.GetName.Name)
Console.WriteLine("-> Version: {0}", a.GetName.Version)
Next
End Sub
Sub anotherAD_DomainUnload(ByVal sender As Object, ByVal e As EventArgs)
Console.WriteLine("***** Unloaded anotherAD! *****")
End Sub
Sub defaultAD_ProcessExit(ByVal sender As Object, ByVal e As EventArgs)
Console.WriteLine("***** Unloaded defaultAD! *****")
End Sub
End Module
|