title: How do I report progress on loading assemblies into the Current AppDomain in .Net on a splash screen?
body: <p>I'm having a little difficulty in displaying the progress of assemblies being loaded into the AppDomain.CurrentDomain.</p>
  
  <p>What I want to do is display a splash screen that has a progress bar, I want to be able to update this Progress bar as each assembly is loaded into memory in the AppDomain. This way users will have a visual indicator as to the progress of the application launch.</p>
  
  <p>I don't care that assemblies are loaded before the Splash Screen is rendered which is actually just a standard WPF Window with a progress bar. Once a Splash Screen is loaded I would like to report the assemblies as they are loaded. I am not manually loading these Assemblies.</p>
  
  <p>So far I have handled the Startup event in App.xaml with the following markup:</p>
  
  <pre><code>Startup="Application_Startup"
  </code></pre>
  
  <p>The corresponding code behind for startup is as follows:</p>
  
  <pre><code>private void Application_Startup(object sender, StartupEventArgs e)
  {
  SplashScreen.Show&lt;SplashScreen&gt;();
  AppDomain.CurrentDomain.AssemblyLoad += CurrentDomain_AssemblyLoad;
  }
  
  void CurrentDomain_AssemblyLoad(object sender, AssemblyLoadEventArgs args)
  {
      SplashScreen.CallSplashScreenMethod&lt;SplashScreen&gt;(x =&gt; x.Text(args.LoadedAssembly.GetName().Name));
  }
  </code></pre>
  
  <p>This works as I expect it, a splash screen is displayed and whatever assemblies are being loaded at the moment the splash screen is displayed are showed on screen without a problem.</p>
  
  <p><img src="https://i.stack.imgur.com/PsS88.png" alt="splashscreen"></p>
  
  <p>The problem here is that I can't see a way of reporting progress of assemblies being loaded.</p>
  
  <p>Assemblies don't seem to be loaded linearly in any particular order, due to this I am not sure how to go about getting a count of the remaining number of assemblies to be loaded. I can't see an obvious way to <strong>get what assemblies are currently being loaded</strong>. </p>
  
  <p>If I could get a list of assemblies yet to be loaded by the CLR I could implement a progress bar by using either a standard count, along the lines</p>
  
  <pre><code>progress = numberOfLoadedAssemblies / totalNumberOfAssemblies * 100;
  </code></pre>
  
  <p>Or by implementing the logic from <a href="https://stackoverflow.com/a/25556115/1396796">Chris Marisic's excellent answer on using a weighted average</a></p>
  
  <p>I can't do a trivial "<strong>Directory.GetFiles().Length</strong>" To get the total number of assemblies to be loaded. The reason why is because the CLR isn't loading 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.</p>
  
  <p>What I'd like to know is if there is a way to get a list of <strong>remaining assemblies</strong> to be loaded.</p>