I’m trying to create a splash screen that shows assemblies (all referenced library) loading status. I use AppDomain.AssemblyLoad AssemblyLoadEventHandler delegate to catch what assembly is being loaded but the problem is the event is not triggered when the program initializes. I tried register the event handler in application startup ‘MyApplication_Startup’ but it didn’t work. Here’s my test code:
Partial Friend Class MyApplication Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup AddHandler AppDomain.CurrentDomain.AssemblyLoad, AddressOf MyAssemblyLoadEventHandler End Sub Sub MyAssemblyLoadEventHandler(ByVal sender As Object, ByVal args As AssemblyLoadEventArgs) Console.WriteLine('>>> ASSEMBLY LOADED: ' + args.LoadedAssembly.FullName) Console.WriteLine() End Sub End Class
One issue you are going to run into is that assemblies in .Net are not loaded until they are needed.
For instance, create a new assembly with a ‘Hello World’ class in it, reference it with any executable, then delete the new assembly from the working directory, at no time will you notice that it is loaded.
Next, on a button click event, initialize the ‘Hello World’ class, keep the assembly deleted from the working directory, and you will receive the error that the assembly can not be found when the button is clicked.
This is the key reason that first database access is generally slow in .Net, and has a ‘speed up’ feel to it (more you use it, the faster it gets), that is because the objects you use in your data layer are not loaded into the runtime until they are accessed.