How to report the progress of loading assemblies into the current AppDomain in .Net on the splash screen?

It’s a little difficult for me to display the progress of assemblies loaded in AppDomain.CurrentDomain.

What I want to do is to display a splash screen that has a progress bar, I want to update this progress bar as each assembly is loaded into memory in AppDomain. Thus, users will have a visual indicator of the progress of launching the application.

I don’t care that the assemblies are loaded before the Splash screen is displayed, which is actually a standard WPF window with a progress bar. When the Splash screen is loaded, I would like to tell the assemblies when they are loaded. I do not manually download these assemblies.

So far, I have been handling the Startup event in App.xaml with the following markup:

Startup="Application_Startup" 

The appropriate code to run is as follows:

 private void Application_Startup(object sender, StartupEventArgs e) { SplashScreen.Show<SplashScreen>(); AppDomain.CurrentDomain.AssemblyLoad += CurrentDomain_AssemblyLoad; } void CurrentDomain_AssemblyLoad(object sender, AssemblyLoadEventArgs args) { SplashScreen.CallSplashScreenMethod<SplashScreen>(x => x.Text(args.LoadedAssembly.GetName().Name)); } 

This works as I expect, the splash screen is displayed and all the assemblies that will be loaded the moment the splash screen is displayed are displayed on the screen without any problems.

splashscreen

The problem here is that I don’t see a way to report the progress of loading assemblies.

Assemblies do not seem to load linearly in any particular order, because of this I am not sure how to count the remaining number of assemblies to load. I see no obvious way to get which assemblies are currently loading .

If I could get a list of assemblies that have not yet been loaded by the CLR, I could implement a progress bar using either a standard counter along the lines

 progress = numberOfLoadedAssemblies / totalNumberOfAssemblies * 100; 

Or, implementing logic from Chris Marisik, a great answer to using a weighted average

I cannot execute the trivial " Directory.GetFiles (). Length ". To get the total number of assemblies to download. The reason is that the CLR does not load assemblies in any particular order. It seems to load some assemblies from the application root, then some from the GAC, then more from the application root.

I would like to know if there is a way to get the list of remaining assemblies for download.

+5
source share
1 answer

According to others, you can’t just assume that 9 assemblies out of 10 loaded tools are 90%. However, you can make these assumptions more realistic.

Scan the file information of all the assemblies that will be downloaded, so that you have the size of each assembly. Now create a weighted value for the "average" assembly.

 var totalSize = assemblies.Select(x=> x.FileSize).Sum(); var averageSize = totalSize / assemblies.Count(); var averageChange = averageSize / totalSize; 

Assuming your progress bar is on a scale of 0 to 1, you can simply add averageChange each time another assembly loads.

Or you could actually count the downloaded bytes against the total size for the progress bar. I personally would go with my average method to prevent progress from [-] to [-------------------] from the same assembly. Users are not used to nonlinear changes and are not inclined to trust nonlinear changes. By providing them with a linearly growing progress bar, which ends almost exactly when it loads, people give people a good idea of ​​things that will work soon. Erroneous jumps in the lanes will make users feel that the system is unstable and unreliable.

One thing that I cannot downplay is how easy it is to annoy your users with a progress bar. Nothing annoys users more than a progress bar, which quickly fills hits by 99% and stops. This makes them feel like the program is frozen. They also need a visual indication that between any meter all things are not frozen. They also do not want to sit for a long time for a long time (this means that you count seconds), see how the progress bar fills, and then flips to zero.

+3
source

Source: https://habr.com/ru/post/1201253/


All Articles