0

Following this answer Preload all assemblies (JIT)

a good way to preload all assemblies of an app. could be

Private Sub PreLoadJit()
  For Each type In Assembly.GetExecutingAssembly.GetTypes
    For Each method In type.GetMethods((BindingFlags.DeclaredOnly  _
                Or (BindingFlags.NonPublic  _
                Or (BindingFlags.Public  _
                Or (BindingFlags.Instance Or BindingFlags.Static)))))
      If (((method.Attributes And MethodAttributes.Abstract)  _
                = MethodAttributes.Abstract)  _
                OrElse method.ContainsGenericParameters) Then
        continue For
      End If
      System.Runtime.CompilerServices.RuntimeHelpers.PrepareMethod(method.MethodHandle)
    Next
  Next
End Sub

But when launch the method? I think could be the first method in the MyBase.Load Method, but don't know if i'm right.

And following this older article

https://www.codeproject.com/Articles/31316/Pre-compile-pre-JIT-your-assembly-on-the-fly-or-tr

The author uses a thread to run the method. What about build pre-jit on starting as a method called in the mainthread, or lauch it in a separate thread?

Marcello
  • 438
  • 5
  • 21
  • 1
    Your program's Main() entrypoint would be a logical choice. Finger nails on a black-board, use ngen.exe instead. https://learn.microsoft.com/en-us/dotnet/framework/tools/ngen-exe-native-image-generator – Hans Passant May 10 '18 at 10:12
  • @Hans Passant: thank you very much, honestly two days ago following an old advice you gave (https://stackoverflow.com/questions/26590809/disadvantages-of-runtimehelpers-preparemethod-in-a-windows-service) i test two days of ngen on 2pc, and this morning i finished to uninstall all native images i created in test, but in my app i change the code every week, and appear to me that with ngen you associate a native image to the execution of a program, but every time that you change the program version, or update the code, you should uninstall the old ngen image, and create a new one, am i right? – Marcello May 10 '18 at 10:45
  • It only matters when you deploy the Release build of your program. You certainly don't want to do this while testing the Debug build given the long delay it can cause. Doing that every week is not terribly common. – Hans Passant May 10 '18 at 10:48

0 Answers0